given a file with two columns, separatedly by standard white space
a b c d f g h
how do I output the second column
We can also print multiple columns and insert our custom string in between columns. For example, to print the permission and filename of each file in the current directory, use the following set of commands: $ ls -l | awk '{ print $1 " : " $8 }' -rw-r--r-- : delimited_data. txt ...
You can use the command awk .
join command is used to join the two files based on a key field present in both the files. The input file can be separated by white space or any delimiter.
cut -d' ' -f2
awk '{print $2}'
Because the last line of your example data has no first column you'll have to parse it as fixed width columns:
awk 'BEGIN {FIELDWIDTHS = "2 1"} {print $2}'
Use cut with byte offsets:
cut -b 3
Use sed to remove trailing columns:
sed s/..//
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With