---------------------------AWK Command------------------------------
Q) How to create a file?
Ans - $ cat > test.txt
Hiranya Patra
Rajesh Dash
Suranjan Dash
Sagar Pradhan
Sudipta Mohapatra
Hiranya Kumar Patra
Rakesh Kumar Dash
Q) Print 2nd field values and then 1st field values in the above test.txt file with separated by space?
Ans –Q) Print 2nd and 1st field values with concatenation in above test.txt file?
Ans –
Q) What is the output of the below command?
awk '{print $2 $2}' test.txt
Ans –
Q) Write a command to see the content of above test.txt file by comma separated?
Ans –
Q) Write a command to show total number of fields present in line first and then the line in above
file test.txt?
Ans –
Q) How to search pattern ‘atra’ in above file test.txt?
Ans –
or (print pattern line with total number of words 1st of each line)
Q) How to search patterns ‘atra’ and ‘Sagar’ in above file test.txt?
Ans –
or (print pattern line with total number of words 1st of each line)Q) How to write patterns ‘atra’ and ‘Sagar’ first of each line in above file test.txt?
Ans –
Q) Write a command to print those lines which having total number of words 3 in above
file test.txt?
Ans –
Q) I want to save a print command of awk in a file and as per need I use the file
to print output whenever necessary?
Ans –
Step – 1: - (Create a file and save the print statement in the file)
Step – 2: - (then use the file in awk –f command)
$ awk –f <Command File><File Name for which the command to run>
Q) What is the output of the below command?
$ cat test1.txt
one two three
five
six,two,three
$ awk '{print $2}' test1.txt
Ans –
As it considers six,two,three as one word.
Q) What is the output of the below command?
$ cat test1.txt
one two three
five
six,two,three
$ awk –F , '{print $2}' test1.txt
Ans -
As it considers one two three as one word.
No comments:
Post a Comment