0

I have a file created with person names and a bunch of other things like phone numbers and addresses. I was wondering how could I select just the names of all the persons on that list.

Please note that there are no columns in that list and one person can have more than one name (I mean not only first and last name but middle names as well). Every line is formatted like this:

student number,,,Name_of_student,,,address

for example:

a684932,,,John Liam Anderson,,,Kentucky
a683910,,,Mary Reynold,,,Michigan
...
...

The output should be:

John Liam Anderson 
Mary Reynold 
1
  • 6
    Please edit your question, adding sample input and expected output to it, as well as what you have already tried to solve the problem yourself. – Quasímodo Oct 19 '20 at 11:48
1

Your data appears to be in comma-separated value (CSV) format.

As long as your CSV file is "simple", i.e. none of the comma-separated fields contains strings with commas, and the name is always in field 4 as implied by your example input, the following awk script which uses the , as field separator would do:

awk -F',' '{print $4}' file.txt

If the field values can contain , (e.g. if the name it John Liam Anderson, jr.), this naive approach doesn't work anymore. This is aggravated by the fact that there is no "definitive" standard defining the CSV format (although open-source software is likely to adhere to RFC4180), so handling of such string depends on how the "field-value-commas" are escaped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.