Pages

20 [Latest] AWK Job Interview Questions and Answers PDF


Real Time AWK Interview Questions and Answers PDF


•    How To Print Only Blank Line Of File.?
sed -n '/^$/p' Test_file.txt

•    Write A Command To Print First And Last Line Using Sed Command?
sed  -n ‘1p’ Test_file.txt
sed –n ‘$p’ Test_file.txt

•    Write A Command To Print All Line Except First Line?
sed –n ‘1!p’ Test_file.txt

•    Write A Command 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

•    Write A Command Remove All Empty Lines:
sed '/^$/d' test_file.txt
sed '/./!d' test_file.txt

•    How To Run Awk Command Specified In A File?
awk -f filename

•    Write A Command To Print The Squares Of Numbers From 1 To 10 Using Awk Command?
awk 'BEGIN { for(i=1;i<=10;i++) {print "square of",i,"is",i*i;}}'

•    Write A Command To Find The Sum Of Bytes (size Of File) Of All Files In A Directory.?
ls -l | awk 'BEGIN {sum=0} {sum = sum + $5} END {print sum}'

•    In The Text File, Some Lines Are Delimited By Colon And Some Are Delimited By Space. Write A Command To Print The Third Field Of Each Line.?
awk '{ if( $0 ~ /:/ ) { FS=":"; } else { FS =" "; } print $3 }' filename

•    Write A Command To Print The Line Number Before Each Line?
awk '{print NR, $0}' filename.

•    Write A Command To Print The Second And Third Line Of A File Without Using Nr.?
awk 'BEGIN {RS="";FS="n"} {print $2,$3}' filename

•    Write A Command To Print Zero Byte Size Files?
ls -l | awk '/^-/ {if ($5 !=0 ) print $9 }'

•    Write A Command To Rename The Files In A Directory With "_new" As Postfix?
ls -F | awk '{print "mv "$1" "$1".new"}' | sh

•    Write A Command To Print The Fields In A Text File In Reverse Order?
awk 'BEGIN {ORS=""} { for(i=NF;i>0;i--) print $i," "; print "n"}' filename

•    Write A Command To Find The Total Number Of Lines In A File Without Using Nr?
awk 'BEGIN {sum=0} {sum=sum+1} END {print sum}' filename

Latest AWK Interview Questions for freshers and Experienced pdf

No comments:

Post a Comment