I learned that in awk, $2 is the 2nd column. How to specify the ith line and the element at the ith row and jth column?
Join Stack Overflow to learn, share knowledge, and build your career.
|
|
To print the second line:
To print the second field:
To print the third field of the fifth line:
Edit: Here's an example with a header line and (redundant) field descriptions:
There are better ways to align columns than "\t\t" by the way. |
|||||
|
|
To print the columns with a specific string, you use the // search pattern. For example, if you are looking for second columns that contains abc:
... and if you want to print only a particular column:
... and for a particular line number:
|
|||||
|
|
To expand on Dennis's answer, use
|
|||||||||||||
|
|
Since awk and perl are closely related... Perl equivalents of @Dennis's awk solutions: To print the second line: To print the second field: To print the third field of the fifth line: Perl equivalent of @Glenn's solution: Print the j'th field of the i'th line
Perl equivalents of @Hai's solutions: if you are looking for second columns that contains abc:
... and if you want to print only a particular column:
... and for a particular line number:
|
||||
|
|
|
I found this working command root@gateway:/home/sshuser# aws ec2 describe-instances --instance-ids i-2db0459d |grep 'STATE\|TAG' |awk 'FNR == 1 {print $1}' STATE |
|||
|
|