LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-12-2006, 11:57 AM   #1
marsguy
Member
 
Registered: Nov 2004
Distribution: Red Hat Enterprise & SuSe 10
Posts: 77

Rep: Reputation: 15
is that possible?


Hello

My question is quite long but I think the answer will be quite simple:

I have a directory called "enigma", That "enigma" directory contains several text files, you can say that those text files are resumes which off course contain "name" ana "age" of some people.

what I want to do is grep 2 fields which are: "name" and "age".

And then put the result in one file so it may look something like this

Mark 25
John 29
Emilia 23

is it possible to this using only shell commands, I am not familiar with writing scripts yet.

Thanks
 
Old 04-12-2006, 12:19 PM   #2
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,832

Rep: Reputation: 108Reputation: 108
If you can describe what you want to do, yes, it is possible.
If not, no.
 
Old 04-12-2006, 12:22 PM   #3
geeman2.0
Member
 
Registered: Feb 2005
Location: Ontario, Canada
Distribution: Gentoo, Slackware
Posts: 345

Rep: Reputation: 30
That's going to depend highly on the format of these resumes.
Your typical resume could have the name just about anywhere, which would make it pretty hard to find it automatically.
 
Old 04-12-2006, 12:39 PM   #4
marsguy
Member
 
Registered: Nov 2004
Distribution: Red Hat Enterprise & SuSe 10
Posts: 77

Original Poster
Rep: Reputation: 15
Thanks for the fast replies:

All the files in the "enigma" directory looke like this:


Name : Name
Age : 32
Gender : Male
Home Address : Liberity avenue
phone : 1234567

Thanks again
 
Old 04-12-2006, 01:12 PM   #5
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,832

Rep: Reputation: 108Reputation: 108
Code:
grep 'Age\|Name' yourFile
will give you
Code:
 Name : Name
Age : 32
Then 'cut' 'tr'.... and several other utilities will give you desired format.
Using 'perl' may be easier.
 
Old 04-12-2006, 03:55 PM   #6
marsguy
Member
 
Registered: Nov 2004
Distribution: Red Hat Enterprise & SuSe 10
Posts: 77

Original Poster
Rep: Reputation: 15
kaz2100, Thank you very much

you are great
 
Old 04-13-2006, 02:00 AM   #7
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
I agree that Perl might be ideal for this.

But you can also try something like this:
Code:
for i in `ls resumes`; do
   age=`grep Age $i|cut -d' ' -f3`;
   name=`grep Name $i|cut -d' ' -f3`;
   echo "$name $age";
done
This should work, as long as the format is:
Name<space>:<space>some_name
Age<space>:<space>some_age

Of course, you'll need to change the ls command in the for-loop to give you a list
of the files that contain the "resumes".
 
  


Reply

Tags
nb



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration