Tuesday, October 13, 2015

"sed" helpful commands

Below are some useful commands for daily use......

1) To delete lines between specified words....and save to the same file.

sed -i '/from/,/produced/d' find.txt

sed -e '/from/,/produced/d' find.txt | tee find.txt (try this if above one is not working to save to the same file)...if  this is not removing the first line of the word...

sed -e '/from/,/produced/d' find.txt | sed '1d' | tee find.txt


2) To count the number of lines between specified words...

sed -n '/from/,/produced/p' oracle | sed -n '$='

3) To delete "nth" line in the file and save to the same file....

 sed -e 'nd' find.txt | tee find.txt

4) To delete last line in the file and save to the same file..

sed -e '$d' find.txt | tee find.txt

5) to delete the specific lines and save to the same file....

sed -e '2d;4d' find.txt | tee find.txt

6) to delete the lines that have a specific word...

sed -e '/ABC/d' find.txt | tee find.txt

if want to delete the lines other that the find ones...then do "/!d" instead of "/d"...

7)  to delete the lines which are starting/begining with a specific word.

sed -e '/^LOG/d' find.txt | tee find.txt

8)   to delete the lines which end with the specific word..

,sed -e '/LOG$/d' find.txt | tee find.tx


will add some more going forward....

Hope this helps....



No comments:

Post a Comment

PostgreSql: Useful Commands-

 1)   ************************* Users ***************************  -- List of users with roles assigned: SELECT usename AS role_name,   CASE...