0% found this document useful (0 votes)
12 views1 page

Doc3 DFT

The document provides a series of AWK command examples for processing text files. It includes commands to print the last field of the last line, filter lines with more than four fields, reverse field order, sum values in a specific field, count blank lines, add a title to the file, and format output using printf. Each command is accompanied by its respective syntax for use with 'poem.txt'.

Uploaded by

tulasipalagiri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Doc3 DFT

The document provides a series of AWK command examples for processing text files. It includes commands to print the last field of the last line, filter lines with more than four fields, reverse field order, sum values in a specific field, count blank lines, add a title to the file, and format output using printf. Each command is accompanied by its respective syntax for use with 'poem.txt'.

Uploaded by

tulasipalagiri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

AWK

Execute the below tasks using awk command

1. To print the value of the last field of the last line

Cmd: awk 'END {print $NF}' poem.txt

2. To print the lines contains more than four fields

Cmd: awk 'NF > 4' poem.txt

3. To print the fields in reverse order

Cmd: awk '{for (i=NF; i>=1; i--) printf "%s ", $i; print ""}' poem.txt

4. To print the sum of all values in the field

Cmd: awk '{ sum += $1 } END { print sum }' poem.txt

5. To print the number of blank lines

Cmd: awk 'NF == 0 { count++ } END { print count }' poem.txt

6. To add the title at the top of the file

Cmd: awk 'BEGIN { print "Title" } {print}' poem.txt

7. To print the data using printf

Cmd: awk '{ printf("%s %s\n", $1, $2) }' poem.txt

You might also like