Theodoros Emmanouilidis

Notes & Thoughts

Remove Leading Whitespace Using Sed

February14

Sometimes a data file contains whitespace before the actual data. The following command will remove that whitespace.

1
cat original_file.txt | sed -e 's,^ *,,' > new_file.txt

Replace Spaces & Tabs With Spaces In File

February14

The following command will substitute all tabs & spaces in a file with just spaces. Very usefull if you want to prepare a file as csv or inject the data contained in a database table.

1
sed -r 's/[[:blank:]]/ /g' original_file > new_file

How To Remount As Read-Write A Read Only Filesystem

May18

So simple but yet so usefull!

If you have to deal with a failling disk or similar emergency situations and you have to remount as read-write a read only filesystem….

just type

1
mount -o remount,rw /

ta da!

Make A List With All Unique Items In A List Python

March31

This is just an one-liner, but very useful and convenient.

Suppose we have a python list

list=[1,4,2,3,4,5,6,3,2,6]

and we only want to return a list containing all unique elements of that list. We can use the “set” python command and construct a new list with all the unique elements of the original list.

list_unique(set(list))

print list_unique

[1,2,3,4,5,6]

Python rocks!!

« Older EntriesNewer Entries »