Explore topic-wise InterviewSolutions in Current Affairs.

This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.

1.

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 'BEGIN {sum=0} {sum=sum+1} END {print sum}' filename

2.

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

awk 'BEGIN {ORS=""} { for(i=NF;i>0;i--) print $i," "; print "n"}' filename

3.

Write A Command To Rename The Files In A Directory With "_new" As Postfix?

Answer»

LS -F | awk '{PRINT "mv "$1" "$1".new"}' | sh

ls -F | awk '{print "mv "$1" "$1".new"}' | sh

4.

Write A Command To Print Zero Byte Size Files?

Answer»

LS -L | awk '/^-/ {if ($5 !=0 ) PRINT $9 }'

ls -l | awk '/^-/ {if ($5 !=0 ) print $9 }'

5.

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

awk 'BEGIN {RS="";FS="n"} {print $2,$3}' filename

6.

Write A Command To Print The Line Number Before Each Line?

Answer»

AWK '{PRINT NR, $0}' FILENAME.

awk '{print NR, $0}' filename.

7.

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.?

Answer»

AWK '{ if( $0 ~ /:/ ) { FS=":"; } else { FS =" "; } print $3 }' filename

awk '{ if( $0 ~ /:/ ) { FS=":"; } else { FS =" "; } print $3 }' filename

8.

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}'

ls -l | awk 'BEGIN {sum=0} {sum = sum + $5} END {print sum}'

9.

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;}}'

awk 'BEGIN { for(i=1;i<=10;i++) {print "square of",i,"is",i*i;}}'

10.

How To Run Awk Command Specified In A File?

Answer»

AWK -F FILENAME

awk -f filename

11.

Write A Command Remove All Empty Lines:

Answer»

SED '/^$/d' test_file.txt

sed '/./!d' test_file.txt

sed '/^$/d' test_file.txt

sed '/./!d' test_file.txt

12.

How To Display Even Number Of Records Into One File And Odd Number Of Records Into Another File?

Answer»

AWK 'NR %2 == 0' test_files.txt

awk 'NR %2 != 0' test_files.txt

awk 'NR %2 == 0' test_files.txt

awk 'NR %2 != 0' test_files.txt

13.

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

sed -i -e '1i Header' -e '$a Trailor' test_file.txt

14.

How To Get Only Zero Byte Files Which Are Present In The Directory?

Answer»

LS -ltr| AWK '/^-/ { if($5 ==0) PRINT $9 }'

ls -ltr| awk '/^-/ { if($5 ==0) print $9 }'

15.

Write A Command Delete All Line Except First Line?

Answer»

SED –n ‘1!d’ Test_file.txt

sed –n ‘1!d’ Test_file.txt

16.

Write A Command To Print All Line Except First Line?

Answer»

<P>SED –n ‘1!p’ Test_file.txt

sed –n ‘1!p’ Test_file.txt

17.

Write A Command To Print First And Last Line Using Sed Command?

Answer»

<P>SED -N1P’ Test_file.txt

sed –n ‘$p’ Test_file.txt

sed -n ‘1p’ Test_file.txt

sed –n ‘$p’ Test_file.txt

18.

How To Print Only Blank Line Of File.?

Answer»

<P>SED -N '/^$/p' Test_file.txt

sed -n '/^$/p' Test_file.txt

Previous Next