Sed Awk Commands

download Sed Awk Commands

If you can't read please download the document

Transcript of Sed Awk Commands

Sed/Awk Top Commands(Unix interview questions) In this post i will mention very useful sed/awk commands,These are quite handy in day to day work and also useful in unix interview. How to Print only Blank Line of File. sed -n '/^$/p' Test_file.txt To Print First and Last Line using Sed Command sed -n 1p Test_file.txt sed n $p Test_file.txt To Print all line Except First Line sed n 1!p Test_file.txt Delete all Line except First Line sed n 1!d Test_file.txt How to get only Zero Byte files which are present in the directory ls -ltr| awk '/^-/ { if($5 ==0) print $9 }' How add a First record and Last Record to the current file in Linux sed -i -e '1i Header' -e '$a Trailor' test_file.txt How to display Even number of records into one file and Odd number of records into another file awk 'NR %2 == 0' test_files.txt awk 'NR %2 != 0' test_files.txt Remove all empty lines: sed '/^$/d' test_file.txt sed '/./!d' test_file.txt