Reputation: 385
I have a big file, in which there are blocks like the following:
....
Org Id VIN Plate Registration Error Code
------ -------------------- -------------------- ------------------------------------------
124 aaaaaaaaaaaaaaaaa WI-V-456 Info 1
124 bbbbbbbbbbbbbbbbb DH-BE-1111 Info 2
124 ccccccccccccccccc A-RM-1332 Info 3
124 ddddddddddddddddd S-SH-3333 Info 4
124 eeeeeeeeeeeeeeeee RH-L-360 Info 5
---------------------------------------------------------------------------------------------
....
I just want to extract the column Error Code
of each, how can I do it?
cat ${fichier} | while read line
do
if [ "x${line}" = 'xOrg Id VIN Plate Registration Error Code' ]
then
echo ${line}
##
fi
done
Upvotes: 0
Views: 63
Reputation: 704
You have a few options. @fedorqui has shown one of them using awk, you can also use mixing cut
with grep
:
$ cut -c 50- testfile.txt | grep ^[^-]
Error Code
Info 1
Info 2
Info 3
Info 4
Info 5
which means: cut testfiletxt- show characters from 50 to the end of line (-c 50-
), an then send it to grep
to show only lines which don't start with "-" char.
Upvotes: 0
Reputation: 289525
You can for example use awk
:
$ awk '$NF>0{print $(NF-1), $NF}' file
Error Code
Info 1
Info 2
Info 3
Info 4
Info 5
This will print the penultimate and last fields, in case last one is something like text or numbers.
Upvotes: 1