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

Using AWK command to skip first line and determine if a '/' is in specific column which happens to be a date in a CSV file

Using AWK command to skip first line and determine if a ‘/’ is in specific column which happens to be a date in a CSV file, although for my request the Date field must only be formatted as ‘YYYY-MM-DD’ no Slashes

this is what I have so far but I can’t get it to recognize the Slashes in the Date field (Column 11) in the File and treat it as invalid and print the Record out.

I am not a experienced Script script writer, Please help 🙂

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

awk -F \| '{if(NR > 1) {{$11~/[/]/}}}' $datadir/sys_slate_app_test.csv > "invalid_other.txt"


   awk: fatal: cannot open file `/sys_slate_app_test.csv' for reading (No such file or directory)

awk -F \| '{if(NR > 1) {{$11~/^//}}}' $datadir/sys_slate_app_test.csv > "invalid_other.txt"

   awk: cmd. line:1: {if(NR > 1) {{$11~/^//}}}
   awk: cmd. line:1:                       ^ syntax error

data:

"30"|"958433018"|"999999999"|"11111111"|"202340"|""|"222222222"|"Tyler"|"Ward"|"email328@yahoo.com"|"2022/08/23"|"UG"|"TR"|"0"|"0"|"0"|"2"|"1"|"RD"|"0"|"1"|"2023-03-09"
"30"|"958433018"|"999999999"|"11111111"|"202340"|""|"222222222"|"Tyler"|"Ward"|"email328@yahoo.com"|"2022/09/10"|"UG"|"TR"|"0"|"0"|"0"|"2"|"1"|"RD"|"0"|"1"|"2023-03-09"
"30"|"958433018"|"999999999"|"11111111"|"202340"|""|"222222222"|"Tyler"|"Ward"|"email328@yahoo.com"|"2022-08-23"|"UG"|"TR"|"0"|"0"|"0"|"2"|"1"|"RD"|"0"|"1"|"2023-03-09"
"30"|"958433018"|"999999999"|"11111111"|"202340"|""|"222222222"|"Tyler"|"Ward"|"email328@yahoo.com"|"2022-06-11"|"UG"|"TR"|"0"|"0"|"0"|"2"|"1"|"RD"|"0"|"1"|"2023-03-09"
"30"|"958433018"|"999999999"|"11111111"|"202340"|""|"222222222"|"Tyler"|"Ward"|"email328@yahoo.com"|"2022/08/23"|"UG"|"TR"|"0"|"0"|"0"|"2"|"1"|"RD"|"0"|"1"|"2023-03-09"

>Solution :

You did’t show the expected output in your question so I don’t know if this is correct or not but it implements what you described best I can tell:

$ awk -F'|' '(NR > 1) && ($11 ~ "/")' file
"30"|"958433018"|"999999999"|"11111111"|"202340"|""|"222222222"|"Tyler"|"Ward"|"email328@yahoo.com"|"2022/09/10"|"UG"|"TR"|"0"|"0"|"0"|"2"|"1"|"RD"|"0"|"1"|"2023-03-09"
"30"|"958433018"|"999999999"|"11111111"|"202340"|""|"222222222"|"Tyler"|"Ward"|"email328@yahoo.com"|"2022/08/23"|"UG"|"TR"|"0"|"0"|"0"|"2"|"1"|"RD"|"0"|"1"|"2023-03-09"
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