Register
It is currently Wed Jul 23, 2014 2:07 pm

Help with a bash script - fields.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Wed Oct 13, 2010 5:38 pm   

Joined: Wed Oct 13, 2010 5:33 pm
Posts: 3
Hey Guys,

I'm new here so... nice to meet you all :)

I would like to know if someone can help me out...

I'm using CentOS 5.5 And I want to write a script that gives me two phrases from a .txt file.

untill now, no problem, but... here is the "Tricky" part, the file looks something like this:

<cell data blah blah blah>
<blah="something" blah="some" bla="something">
<blah=something blah="I-WANT-THIS-PHRASE" Blah="something>
< blah blah blah blah="something" blah blah="I-WANT-THIS-PHRASE-2">
now, the thing is that i want the sed or awk or what ever not only to 'egrep' me those phrases but i want it to (>) to a file and in the file i will see in one line (in this specific order): I-WANT-THIS-PHRASE I-WANT-THIS-PHRASE-2

Hope you could help me out here :)

Thanks alot!
un4get.


Top
 Profile  
 PostPosted: Thu Oct 14, 2010 2:00 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
If you already know how to get those phrases, it's almost not tricky at all. Just use
Code:
echo $(get-phrase-1) $(get-phrase-2) > output-file

or something similar.


Top
 Profile  
 PostPosted: Sun Oct 17, 2010 6:17 am   

Joined: Wed Oct 13, 2010 5:33 pm
Posts: 3
meaning - is this a right way? grep /dir/of/file/*.xml | egrep -i '(phrase1|phrase2)' - what from here?

thanks alot!
un4get.


Top
 Profile  
 PostPosted: Tue Oct 19, 2010 4:41 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
No, it is not. Just one (e)grep is enough:
Code:
egrep -i '(phrase1|phrase2)' /dir/of/file/*.xml > output.txt

But be careful. You are probably working with XML or SGML, so using a parser might save you troubles later.


Top
 Profile  
 PostPosted: Thu Oct 21, 2010 4:25 pm   

Joined: Wed Oct 13, 2010 5:33 pm
Posts: 3
sorry of the lack of knowledge but i still don't understand how to put the two phrases I Want from *.xml files and put the in a phrase1 phrase2 order...


Top
 Profile  
 PostPosted: Fri Oct 22, 2010 3:08 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
Could you give a more detailed specification?


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP