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
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
if the input file looks like the above, this should work
sed -e 's/^\([^[:space:]]\)[[:spa ce:]]\(.*\ )$/\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
sed -e 's/^\([^[:space:]]\)[[:spa
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?