0

So, my Problem is that I have a file with a lot of names in it, and I want to extract Information by using a command. I want a few of the Names starting with a specific last name..for example "d". It's a really big list and I want to facilitate the work.

2
  • 2
    Could you give us an example of the list of names, and an example of the output you would like?
    – Gsxr1k
    Dec 6, 2015 at 13:44
  • en.wikipedia.org/wiki/Marathon_year_rankings this ranking for example, and i would like to exclude all people in this list featuring a d in the name.
    – MassU
    Dec 6, 2015 at 14:28

2 Answers 2

1

Using the example you gave, first we need to get the data from the webpage. I copied the first table, pasted it into a spreadsheet (LibreCalc in my case), then exported it as a csv file to list.csv. The resulting file looks like this:

1921,2:47:29.8,Florestano Benedetti (ITA),1921-09-20,Bologna,Italy
1922,2:46:26,Gabriel Ruotsalainen (FIN),1922-09-10,Helsinki,Finland
1923,2:40:47,Aksel Jensen (DEN),1923-06-16,Windsor,England
1924,2:36:10,Shizo Kanaguri (JPN),1924-04-12,Tokyo,Japan
...

Then we can use grep, sed, awk, or anything else to process the file. For example, using awk:

$ cat list.csv | awk -F, '$3 !~ /[Dd]/ { print; }'
1921,2:47:29.8,Florestano Benedetti (ITA),1921-09-20,Bologna,Italy
1923,2:40:47,Aksel Jensen (DEN),1923-06-16,Windsor,England
1937,2:30:38,Manuel Dias (POR),1937-03-28,Lisbon,Portugal
1938,2:30:27.6,Pat Dengis (USA),1938-05-30,Salisbury,Massachusetts,USA
...

This prints out any line where the name (the third column, hence $3) does not contain either a D or a d. See the awk, sed, or grep man pages for further details.

0

Grep

Grep, searches the input files for lines containing a match to a given pattern list.

When it finds a match in a line, it copies the line to standard output by default, or does whatever other sort of output you have requested with options.

Grep can simply be invoked:

grep <string> filename

Grep can search for complicated pattern to find what you need.

Here is a list of some of the special characters used to create a regular expression:

. The period . matches any single character.
? The preceding item is optional and will be matched at most once.
* The preceding item will be matched zero or more times.
+ The preceding item will be matched one or more times.   

For more details check: man grep

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .