Register
It is currently Thu Dec 18, 2014 2:47 am

filter


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Wed Jan 25, 2012 1:46 pm   

Joined: Wed Jan 25, 2012 1:32 pm
Posts: 5
hi ^^
i'm trying to make a filter, because i want this:

from this: (various text=*)
various text <em>ciao1</em>various text
various text <em>ciao2</various text
various text <em>wow</em>various text<em>plop</em>various text

to this:
ciao1
wow
plop

i tried
#!/bin/bash
input_file="$*"
output_file=${input_file}.txt

grep -i '\<%3cem%3e*%3c/em%3e\>' ${input_file} > ${output_file}
or
sed -e '<em>*</em>' ${input_file} > ${output_file}

but nothing work, i just want what's inside <em>*</em> and nothing else, it's so impossible?
thank you :)


Top
 Profile  
 PostPosted: Thu Jan 26, 2012 8:39 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
hi,

don't you want to keep 'ciao2'?


Top
 Profile  
 PostPosted: Fri Jan 27, 2012 12:58 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
An awk(1) solution:

Code:
awk -F '[<>]' '{ for (i = 1; i <= NF; i++) if ($i == "em") print $(++i) }' "$input_file" > "$output_file"


Top
 Profile  
 PostPosted: Mon Jan 30, 2012 12:22 pm   

Joined: Wed Jan 25, 2012 1:32 pm
Posts: 5
jsz wrote:
An awk(1) solution:

Code:
awk -F '[<>]' '{ for (i = 1; i <= NF; i++) if ($i == "em") print $(++i) }' "$input_file" > "$output_file"


thx a lot, it worked perfectly, i didn't know how useful can be awk, thanks :)
8->


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 1 guest


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:  


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