sed/awk print out


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed/awk print out
# 1  
Old 04-20-2009
sed/awk print out

guys...

i'm currently trying to parse some html code:

Code:
 <tr class="first"  name="bc_10934363" class=""><td class="col1"><div class="ctitle">Some text</div><div class="crec" name="pc_10934363"></div><div class="ctext">Some text</div></td><td class="col2"><div class="ctext">SF zwei</div></td><td class="col3"><div class="ctext">Thursday<br/>23.04.2009<br/>22:55</div></td></tr>

This <tr>...</tr> is one line. At the end i need something like this:

Code:
10934363;Thursday;23.04.2009;22:55

At the moment I use sed:

Code:
sed 's/<tr class=\"first\"  name=\"bc_/;/g'

for example. So on the end I have 10 or more sed statements. I now like to do it in a better way.

Any ideas?

cheers
# 2  
Old 04-20-2009
try this:

sed -n 's/<tr .*=\"bc_\([0-9][0-9]*\)\".*\"ctext\">\(.*\)<br\/>\(.*\)<br\/>\(.*\)<\/div.*tr>$/\1;\2;\3;\4/p' filename


cheers,
Devaraj Takhellambam
# 3  
Old 04-20-2009
the earlier one was just for printing...

sed 's/<tr .*=\"bc_\([0-9][0-9]*\)\".*\"ctext\">\(.*\)<br\/>\(.*\)<br\/>\(.*\)<\/div.*tr>$/\1;\2;\3;\4/g' filename



cheers,
Devaraj Takhellambam
# 4  
Old 04-20-2009
wow that was quick and works for me! thanks devtakh.

But what happens if the content of <tr>...</tr> will change a little bit?

Is it not possible to search on given expressions and just print these out?

For example:
Code:
10934363;Thursday;23.04.2009;22:55 <-- This is the string i need

[0-9]{8} = 10934363
[Aa-Zz]{at least 6 times} = Thursday
??? = 23.04.2009
??? = 22:55

So in fact i like to search on my needed parts and print these out. I hope you know what i mean.

thanks so much
# 5  
Old 04-20-2009
I guess i know what you mean..


sed 's/<tr.*\([0-9]\{8\}\).*ctext\">\([aA-zZ]\{6,\}\).*\([0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{4\}\).*\([0-9]\{2\}:[0-9]\{2\}\).*tr>$/\1;\2;\3;\4/g' filename

but i wud like to have ctext in the search patter as it cud otherwise match anything..


cheers,
Devaraj Takhellambam
# 6  
Old 04-20-2009
thanks so much devtakh!

This is exactly what i need. One last thing:

Do you know why there is some space in front of the first string?

Code:
 more file.out | sed 's/<tr.*\([0-9]\{8\}\).*ctext\">\([aA-zZ]\{6,\}\).*\([0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{4\}\).*\([0-9]\{2\}:[0-9]\{2\}\).*tr>$/\1;\2;\3;\4/g'
                    10934363;Donnerstag;23.04.2009;22:55
                    10934365;Freitag;24.04.2009;03:15
.................... <- This space i mean.

# 7  
Old 04-20-2009
dont use more...there is no need
just use sed and filename like what i had given initially..



cheers,
Devaraj Takhellambam
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print & and \n while replacing with sed/awk?

string="din&esh\nisgood" File.txt: the name is sed "s#\#${string}#g" File.txt Output am getting: the name is dinesh is good Expected output: the name is din&esh\nisgood The input string is dynamic it will be keep on changing am able to handle & by placing \& in the string.. (5 Replies)
Discussion started by: dineshaila
5 Replies

2. Shell Programming and Scripting

How to print the lines between the pattern using awk/grep/sed?

Hi, I need a help to search a pattern and print the multiple lines between them. Input file: Tue May 29 12:30:33 EDT 2012:threadWebContainer : 357:com.travimp.hotelierlinks.abba.service.RequestHandler.requestService(String, ITICSDataSet): hotelCancelReservation request: ... (4 Replies)
Discussion started by: aroragaurav.84
4 Replies

3. Shell Programming and Scripting

Sed/awk print between different patterns the first occurrence

Thanks for the help yesterday. I have a little modification today, I am trying the following: i have a log file of a webbap which logs in the following pattern: 2011-08-14 21:10:04,535 blablabla ERROR Exception1 blablabla bla bla bla bla 2011-08-14... (2 Replies)
Discussion started by: ppolianidis
2 Replies

4. Shell Programming and Scripting

print pattern between two variables awk sed

I am trying to print text between two variables in a file I have tried the following things but none seem to work: awk ' /'$a'/ {flag=1;next} /'$b'/{flag=0} flag { print }' file and also sed "/$a/,/$b/p" file But none seem to work Any Ideas? Thanks in Advance (5 Replies)
Discussion started by: forumbaba
5 Replies

5. Shell Programming and Scripting

sed or awk to print 2nd last word

Hi, I have a file which has the following /usr/new/xyz/abc /us1/neb/yxr/def /usr/bin/cloud1/fgh /net/bin1/txt1/kdq I want to do something like this /usr/new/xyz/abc xyz /us1/neb/yxr/def yxr /usr/bin/cloud1/fgh cloud1 /net/bin1/txt1/kdq txt1 I need to add the 2nd last word to the... (3 Replies)
Discussion started by: matbrow
3 Replies

6. Shell Programming and Scripting

Help with sed/awk for reverse search and print

I have a file which is DFDG START DSFDS DSDS XXX END (VIO) AADD START SDSD FGFG END and I have to print the lines between START and END (VIO). In the files there are multiple places where START would be followed by END with few lines in between but I need to print only if START is... (18 Replies)
Discussion started by: pgbuddy
18 Replies

7. Shell Programming and Scripting

Awk/Sed: Search Pattern from file and Print

Hi, I want to search for patterns (from a file) in a file and print the line matching the patterns and the line before it. I have to search for 100s of patterns from a file. Any help with AWK or Sed. Thanks! (2 Replies)
Discussion started by: saint2006
2 Replies

8. Shell Programming and Scripting

Awk , Sed Print last 4 numeric characters

Hello All, I have been searching and trying this for a bit now. Can use some assistance. Large 5000 line flat file. bash, rhel5 Input File Sinppet: Fri Oct 30 09:24:02 EDT 2009 -- 1030 Fri Oct 30 09:26:01 EDT 2009 -- 73 Fri Oct 30 09:28:01 EDT 2009 -- 1220 Fri Oct 30 09:30:01 EDT... (9 Replies)
Discussion started by: abacus
9 Replies

9. UNIX for Dummies Questions & Answers

Sed | Awk | Print

Hello, ı want to started shell programing. But first, I want to learn ssh code. How can I use this codes ( sed - awk - print ). How do codes work? Thanks.. Best Wishes.. (1 Reply)
Discussion started by: Nullsix
1 Replies

10. UNIX for Dummies Questions & Answers

using awk or sed to print output from one file

dear i have one file regarding >abshabja>sdksjbs>sknakna>snajxcls so i want to be output like >abshabja >sjkabjb >sknakna >snajxcls Any using awk or sed will help thanks (2 Replies)
Discussion started by: cdfd123
2 Replies
Login or Register to Ask a Question