An AWK is a software programming language. It is mainly used for processing the text and for extracting data and to report the information. People who use Unix operating systems, AWK is the standard. AWK prominently uses string datatype, arrays and regular expressions. The commands has the statements that will be executed. They include variable assignments, calculations, function calls etc. AWK provides built in support to many functions. There are several positions available for this job all over the globe. Wisdomjobs focus on providing interview questions and answers to help you in clearing the interview with ease. AWK interview questions and answers are useful to attend job interviews and get shortlisted for job position. Check out interview questions page to get more information.
Question 1. How To Print Only Blank Line Of File.?
Answer :
sed -n '/^$/p' Test_file.txt
Question 2. Write A Command To Print First And Last Line Using Sed Command?
Answer :
sed -n ‘1p’ Test_file.txt
sed –n ‘$p’ Test_file.txt
Question 3. Write A Command To Print All Line Except First Line?
Answer :
sed –n ‘1!p’ Test_file.txt
Question 4. Write A Command Delete All Line Except First Line?
Answer :
sed –n ‘1!d’ Test_file.txt
Question 5. How To Get Only Zero Byte Files Which Are Present In The Directory?
Answer :
ls -ltr| awk '/^-/ { if($5 ==0) print $9 }'
Question 6. How Add A First Record And Last Record To The Current File In Linux?
Answer :
sed -i -e '1i Header' -e '$a Trailor' test_file.txt
Answer :
awk 'NR %2 == 0' test_files.txt
awk 'NR %2 != 0' test_files.txt
Question 8. Write A Command Remove All Empty Lines:
Answer :
sed '/^$/d' test_file.txt
sed '/./!d' test_file.txt
Question 9. How To Run Awk Command Specified In A File?
Answer :
awk -f filename
Question 10. Write A Command To Print The Squares Of Numbers From 1 To 10 Using Awk Command?
Answer :
awk 'BEGIN { for(i=1;i<=10;i++) {print "square of",i,"is",i*i;}}'
Question 11. Write A Command To Find The Sum Of Bytes (size Of File) Of All Files In A Directory.?
Answer :
ls -l | awk 'BEGIN {sum=0} {sum = sum + $5} END {print sum}'
Answer :
awk '{ if( $0 ~ /:/ ) { FS=":"; } else { FS =" "; } print $3 }' filename
Question 13. Write A Command To Print The Line Number Before Each Line?
Answer :
awk '{print NR, $0}' filename.
Question 14. Write A Command To Print The Second And Third Line Of A File Without Using Nr.?
Answer :
awk 'BEGIN {RS="";FS="n"} {print $2,$3}' filename
Question 15. Write A Command To Print Zero Byte Size Files?
Answer :
ls -l | awk '/^-/ {if ($5 !=0 ) print $9 }'
Question 16. Write A Command To Rename The Files In A Directory With "_new" As Postfix?
Answer :
ls -F | awk '{print "mv "$1" "$1".new"}' | sh
Question 17. Write A Command To Print The Fields In A Text File In Reverse Order?
Answer :
awk 'BEGIN {ORS=""} { for(i=NF;i>0;i--) print $i," "; print "n"}' filename
Question 18. Write A Command To Find The Total Number Of Lines In A File Without Using Nr?
Answer :
awk 'BEGIN {sum=0} {sum=sum+1} END {print sum}' filename
AWK Related Tutorials |
|
---|---|
AWK Tutorial | Sed (Stream Editor) Tutorial |
AWK Related Interview Questions |
---|
Sed (Stream Editor) Interview Questions |
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.