Reputation: 3105
I have a file
tadjag:x:60697:100:Name Surname IF-3/4 2015-02-02:/export/home/tadjag:/bin/bash
linbul:x:60698:100:Name2 Surname2 IF-3/4 2015-02-02:/export/home/linbul:/bin/bash
sarvis:x:60699:100:Name3 Surname3 IF-3/2 2015-02-02:/export/home/sarvis:/bin/bash
deigru:x:60701:100:Name4 Surname4 IF-3/4 2015-02-02:/export/home/deigru:/bin/bash
tauilc:x:60702:100:Name5 Surname5 IF-3/3 2015-02-02:/export/home/tauilc:/bin/bash
...
...
...
...
and I want to take only Name's and Surname's if they are from IF-3/4
. So my result should be
Name Surname
Name2 Surname2
Name4 Surname4
what I done
awk -F: '{print $5}' myFile
So my output is
Name Surname IF-3/4 2015-02-02
...
...
So is it possible to get only Name's and Surname's if they are from IF-3/4
Upvotes: 0
Views: 85
Reputation: 1517
awk -F'[: ]' 'NR<2||!(NR%2){print $5,$6}' file
Name Surname
Name2 Surname2
Name4 Surname4
Upvotes: 0
Reputation: 174696
Use awk's split function to split on spaces which exists on the column 5 and again it stores the splitted values to an associate array a
. So a[1]
contains the first word (Name) and a[2]
contains the second word (Surname).
$ awk -F: '{split($5,a,/[[:blank:]]+/); print a[1],a[2]}' file
Name Surname
Name2 Surname2
Name3 Surname3
Upvotes: 1