Search code examples
awkechocat

How to print odd line in unix


In a file, value '20210813_20210816_20210818' and '20210813_20210816' are coming in newline. In the below issue there are 2 DB records but coming in 4 lines instead of 2 . I want to print that two values which I mentioned using unix script.

This is not working:

cat filename.txt| awk 'NF' | while read n

do

10th_colum =`echo $n | awk 'NF'| awk '{print $10}'`

done

input:

20210908 ABC  ICICI            EFT  Rcvd     Staging Not_Rcvd Not_Rcvd Not_Dlvrd
20210813_20210816_20210818
20210908 CDE  HDFC            EFT  Rcvd     Staging Not_Rcvd Not_Rcvd Not_Dlvrd
20210813_20210816

Solution

  • $ awk '!(NR%2)' file
    20210813_20210816_20210818
    20210813_20210816