I have an AWK script that uses multiple delimiters in the FS variable.
FS="[\. _]+"
My awk script takes a file name such as this:
12345_smith_bubba_12345_20120215_4_0.pdf and parses it out based on the under score. Each parsed field then has some code for data validation etc.
This script has been working fine until I got a file name like this:
12345_smith johnson jones_bubba_12345_20120215_4_0.pdf
Where the last name field has three last names separated by a space.
Is there a way in my FS assignment to tell AWK to ignore the whitespace and just use the period "." and underscore "_" as the only delimiters?
I am reluctant to suppress the space from the -F list , since if the coder added it to the list, maybe it is used to process some further step in the awk script. So if you remove it, you have to make sure that it has no impact on the remaining awk code.
Bartus - That was the first thing I tried and still got the same result.
ctsgnb - The script's purpose is to create an "index" file used by an application to import PDF's for viewing. The application will have the person's name preloaded. So when it looks to the index file for the person's name, it has to be exact or it will fail to import. So the name has to maintain the spaces.
Thank you for replying so fast!
---------- Post updated at 10:44 AM ---------- Previous update was at 10:43 AM ----------
Hi, I used this to check if there was an anomaly with your particular awk, but it looks OK, so Bartus11' suggestion would seem to work after all.
Just change OFS to underscore for the desired output and puy a dot between $7 and $8: