substr(string, start, length)
This returns a length-character-long substring of string, starting at character number start. The first character of a string is character number one. For example, substr("
The descriptions about the "AWK Built-in Functions for String Manipulation" can be found here:
The following example will clear your understanding about the same function.
$ cat file.txt
FAN01MMAS2not set ahxpx0c1
FAN04MMAS4not set ptyx0c2
FAN02MMAS5not set 01cx67u
FAN06MMAS6not set opertxh2
FAN07MMAS2not set 9mcxh
FAN03MMAS8not set ptyx0c2
Required Output:
--------------------
FAN01 (not set) MMAS2 ahxpx0c1
FAN04 (not set) MMAS4 ptyx0c2
FAN02 (not set) MMAS5 01cx67u
FAN06 (not set) MMAS6 opertxh2
FAN07 (not set) MMAS2 9mcxh
FAN03 (not set) MMAS8 ptyx0c2
$ awk '{
one=substr($0,1,5)
two=substr($0,6,5)
three=substr($0,11,7)
rest=substr($0,19)
printf ("%s (%s) %s %s\n", one, three, two, rest)
}' file.txt
No comments:
Post a Comment