I have a file which contains fields comma separated & with each field surrounded by quotes. The 4th field contains either a serial number, the text ABC, the text XYZ or it's blank. I want to only extract records which have a serial number. Here's some sample data:
> cat myfile
"ABC123","00CJ","SP16","","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","00240095028","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","ABC","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","00240104067","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","XYZ","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","XYZ","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","00240025035","SP265","","S248","19/05/2003"
>
I thought I could do this using this command but I now realise that the .* construct selects the entire string until it finds a field which satisfies [0-9].* This means that all fields are selected.
> grep "\".*\",\".*\",\".*\",\"[0-9].*\"" myfile
"ABC123","00CJ","SP16","","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","00240095028","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","ABC","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","00240104067","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","XYZ","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","XYZ","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","00240025035","SP265","","S248","19/05/2003"
>
What I want are just these records:
"ABC123","00CJ","SP16","00240095028","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","00240104067","SP265","","S248","19/05/2003"
"ABC123","00CJ","SP16","00240025035","SP265","","S248","19/05/2003"
There must be a simple way to select only records with a 4th field that is a numeric value. Can anyone advise please?
Thanks, Chris