czwartek, 27 kwietnia 2017

sed handy examples

example file:

-> cat test.file
1 file
2 line
3 lin
4 l
5
#6 comment

1. delete first line from file

sed -e '1d' test.file
bunny-> sed -e '1d' test.file
2 line
3 lin
4 l
5
#6 comment


2. delete lines 1,2,3 from file
sed -e '1,3d' test.file
bunny-> sed -e '1,3d' test.file
4 l
5
#6 comment

3. delete lines started with '#'
sed -e '/^#/d' test.file
bunny-> sed -e '/^#/d' test.file
1 file
2 line
3 lin
4 l
5

4. change char to string
bunny-> sed -e 's/l$/another line/' test.file
1 file
2 line
3 lin
4 another line
5
#6 comment

5. insert double/single spaces between lines
ansible-> sed 'G;G' test.file - for double
ansible-> sed G test.file - for single
1 file


2 line


3 lin


4 l


5


#6 comment


7 l


8 l


6. 

Brak komentarzy:

Prześlij komentarz