![]() |
Shell script to read lines in a text file and filter user data
hi all,
I have this file [myfile.txt] with some user data. example: $cat myfile.txt FName|LName|Gender|Company|Branch|Bday|Salary|Age aaaa|bbbb|male|cccc|dddd|19900814|15000|20| eeee|asdg|male|gggg|ksgu|19911216||| aara|bdbm|male|kkkk|acke|19931018||23| asad|kfjg|male|kkkc|gkgg|19921213|14000|24| aera|bprb|male|cccc|pppp||15000|20| . . . // and so on So what I want to do is to take out (to a file) the missing fields as following format: <FName> <LName> <Company> Missing Field/s:<> <> example output: eeee asdg gggg Missing Field/s: Salary Age aara bdbm kkkk Missing Field/s: Salary CAN ANYONE HELP ME PLEASE !!!!!!!!!!!!!!! |
Hi,
I do have to assume things to solve this: 1) fields 1, 2 and 4 (FName, LName and Company) are always present, 2) rest of the fields could be missing. I came up with this: Code:
#!/bin/bashQuote:
|
Thank you
Thank you very much....for your great help.
:D Quote:
|
Code:
awk 'BEGIN{FS="|"} |
@ghostdog74:
Nice solution, but...... 1) It prints all the lines, not just the faulty ones, 2) The "Missing Field/s:" part is missing in your output. |
Quote:
2) i left the output un-formatted for the OP to do if he desires. What is important is the logic |
| All times are GMT -5. The time now is 07:28 AM. |