Remove Leading Whitespace Using Sed
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 |
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 |
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 |
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!
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!!