Suppose that we have file like this:
sometext11 sometext12 sometext13 sometext21 sometext22 sometext23
Texts are separated by tabs and we know sometext from column 1 but want to get text from column 2. I know I can get line by:
grep 'sometext11' file.txt
How to get text from second column? Maybe some tool with option -t [column nr]?
awk:
awk '{print $2}' file.txt
cut:
cut -f2 file.txt
bash:
while read -a A; do echo ${A[1]}; done < file.txt
perl:
perl -lane 'print $F[1]' file.txt
If you know the string you are grepping for, you can use grep
:
grep -o 'sometext12' file.txt
awk '{print $2}' < yourfile
You can use cut command
cut -f2
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