Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AWK script to print a single next word following a pattern match from Description field

I have below CSV file:

CreateDate, First Name, Last Name, Description
2023/03/25, Makvala, Anima, Your orders are 6157 and total value is 854257
2023/03/26, Leobwin, Saturnus, Your orders are 72 and total value is 1575675
2023/03/25, Boadicea, Pradip, Your orders are 52116 and total value is 29344357

I want below output

Orders: 6157, Total Value: 854257
Orders: 72, Total Value: 1575675
Orders: 52116, Total Value: 29344357

I already looked for a couple of similar questions on StackOverflow, but they are extracting the word considering there is only 1 field and then separating using orders are , but I have multiple fields and I want to get the values from Description field.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any help would be much appreciated.

>Solution :

Like this with nawk, mawk, gawk, busybox awk:

awk -F, '
    NR>1{
        split($4, a, / +/)
        print "Orders:", a[5] ",", "Total Value:", a[10]
    }
' file

Output

Orders: 6157, Total value: 854257
Orders: 72, Total value: 1575675
Orders: 52116, Total value: 29344357
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading