Link to home
Start Free TrialLog in
Avatar of raj2k1
raj2k1

asked on

how to filter name w.r.t to town in a notepad file

Hello Geeks,

I need to find the names of all those persons in a text file on the basis of town.

for example if the town matches Djibouti,then it should reflect me the name.

I want this in unix environ ment

NAME  RAJ Kumar

DOB 22121987

TOWN DIGBOI

NAME Shanti

DOB 01111986

TOWN ITANAGAR

NAME ROSY

DOB 07082010

TOWN DJIBOUTI
Avatar of arnold
arnold
Flag of United States of America image

Is perl an option?
Is the data in the file as you posted
Name
Dob
Town

Presumably you are aware that this is a help rather than a seemingly homework assignment that experts here will solve for you?

Can you post what script you attempted and have?
Avatar of skullnobrains
skullnobrains

if the input file looks like the above, this should work

sed -e 's/^\([^[:space:]]\)[[:space:]]\(.*\)$/\1="\2"'/ -e 's/^TOWN/&;if test town = "jibouti" ; then echo -e "NAME $NAME\nDOB $DOB\nTOWN $TOWN\n" ; fi/' | sh

beware this will only work providing
-> the format of the file is the one provided without missing lines or lines in a different order
-> the values never contain double-quotes

----

it would probably be easier using awk, perl, ... but here is the shell way
ASKER CERTIFIED SOLUTION
Avatar of skullnobrains
skullnobrains

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial