Print the data from second column

Viewed 81

I am having a file called fixed.txt as shown below:

Column1                   | Column2 | Column3
Total expected ratio      | 53      | 68
Total number|count number | 54      | 72
reset|print|total         | 64      | 84

I am trying to print the output column2 as below:

Fixed.txt:
53
54
64

I tried the below script but I am not getting the desired output.

#!/bin/bash
for d in fixed.txt
do
awk -F" | "
    NR>1
    awk '{ print $2 }' fixed.txt
done

Can we use pipeline(|) and space at a time as a delimiter?

1 Answers

1st solution: Could you please try following based on your shown samples it's written. Written and tested in https://ideone.com/WoF40j

awk '
BEGIN{
  FS="|"
}
{
  print $(NF-1)+0
}
' Input_file


2nd solution: Use space and | as a field delimiter one could run following.

awk -F'[[:blank:]]+\\|[[:blank:]]+' '{print $(NF-1)}'  Input_file

OR

awk -F' +\\| +' '{print $(NF-1)}' Input_file
Related