Nothing Special   »   [go: up one dir, main page]

Sed Awk Commands

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Sed/Awk Top Commands(Unix interview questions)

In this post i will mention very useful sed/awk commands,These are quite handy i
n 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 in
to 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

You might also like