Awk substr function


Let's look at the substr function of awk.
This function has the form substr(s, a, b) and returns b number of chars from string s, starting at position a.  The parameter b is optional.

Example- Let you have a file 'test' with the following test in it.

ABCDE FGHIJK LMNOPQ RST UVWX

awk '{print substr($1,1,1)}' test
awk '{print substr($1,3)}' test
awk '{print substr($3,3)}' test
awk '{print substr($4,3)}' test
awk '{print substr($0,5,2)}' test


Run these commands and understand how this works....

This entry was posted by Unknown. Bookmark the permalink.

Leave a Reply