Sed/Perl help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed/Perl help
# 1  
Old 01-22-2011
Error Sed/Perl help

Some text is like this....
Code:
<table>This is first text.</table>mouse
<table>This is second text</table>keyboard
<table>This is third text</table>Pad

I need to insert <a></a> between "mouse","keyboard","Pad".
I it possible to do with sed/Perl ? Please help..

The text should look like this.
Code:
<table>This is first text.</table><a>mouse</a>
<table>This is second text</table><a>keyboard</a>
<table>This is third text</table><a>Pad</a>


Last edited by Scott; 01-22-2011 at 01:07 PM.. Reason: Code tags
# 2  
Old 01-22-2011
Code:
perl -pe 's/\w+$/<a>$&<\/a>/' file

# 3  
Old 01-22-2011
Bug

Can you explain the code please ? Smilie
# 4  
Old 01-22-2011
With sed:
Code:
sed 's/[^>]*$/<a>&<\/a>/' file

With awk:
Code:
awk -F\> '{$NF="<a>"$NF"</a>"}1' OFS=\> file

# 5  
Old 01-22-2011
Code:
 $ ruby -pne 'chomp;gsub(/>(.[^>]*)$/,">\\1\n")' file

# 6  
Old 01-24-2011
Error

If the file content has many tags , what shall I do ?

like <h> <br> other than <keywords> tag ?
# 7  
Old 01-24-2011
Quote:
Originally Posted by gameboy87
If the file content has many tags , what shall I do ?
Provide a better example of the input file and the desired output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rewrite sed to perl or run sed in perl

I am having trouble re-writing this sed code sed -nr 's/.*del(+)ins(+).*NC_0{4}(+).*g\.(+)_(+).*/\3\t\4\t\5\t\1\t\2/p' C:/Users/cmccabe/Desktop/Python27/out_position.txt > C:/Users/cmccabe/Desktop/Python27/out_parse.txt in perl Basically, what the code does is parse text from two fields... (12 Replies)
Discussion started by: cmccabe
12 Replies

2. Shell Programming and Scripting

Perl sed question

Hi, I'm trying to use perl the way I use sed. Lets say I have this command: $ echo abc | sed 's/abc/&&/' abcabcIf I try this with perl, I end up with this: $ echo abc | perl -pe 's/abc/&&/' &&How do I make the '&' sign work? Another thing that I can't get with perl is this: $ echo... (4 Replies)
Discussion started by: Subbeh
4 Replies

3. Shell Programming and Scripting

awk sed perl??

Hi guys First of all a salute to this wonderful platform which has helped me many a times. Im now faced with something that I cannot solve. I have data like this 11:14:18 0.46975 11:14:18 0.07558 11:14:18 0.00020 11:14:18 0.00120 11:14:18 0.25879 11:14:19 0.00974 11:14:19 0.05656... (13 Replies)
Discussion started by: jamie_123
13 Replies

4. Shell Programming and Scripting

re-Substitution Sed (or Perl)

I have a large text csv file that I'm working with. It will look something like this: D,",E",C O,"F,",I O,gh,R The second column always has a two digit random code (can be numbers, letters or any characters). When one of the characters happens to be a comma, the string is quoted. I want to... (5 Replies)
Discussion started by: beenny
5 Replies

5. Shell Programming and Scripting

Need Help with sed/perl !

In a file the content is 13 box google unix.com "he is google" hello "he is unix.com" - I need to replace each space char with "a" char but not inside the double quoted strings. So, the output must look like, 13aboxagoogleaunix.coma"he is google"ahelloa"he is unix.com"a- I tried with ... (9 Replies)
Discussion started by: gameboy87
9 Replies

6. Shell Programming and Scripting

Problem with sed in perl!!

Hi, I am facing an issue with sed in perl. I have a file which has 2 header lines and one trailer line. I need to process the file without these headers and trailer. My file looks like : File.txt:- Header1 Header2 data1 data2 trailer For removing header and trailer from file I am using... (5 Replies)
Discussion started by: abhisharma23
5 Replies

7. Shell Programming and Scripting

Convert sed to perl

Can anyone convert this from sed to perl: sed -n '/\var\/log/p' /etc/syslog.conf I think Ive looked at this to much....urgh.. Thanks Ben (5 Replies)
Discussion started by: bigben1220
5 Replies

8. UNIX for Advanced & Expert Users

Use of SED in Perl or any other options

Hi Folks, I am working on a data extraction script in perl.I am a begineer in perl and shell scripting. So i need your inputs to solve the script problem. I have data coming from database in the format :- <b> _ABC (Apply Changes) (p) </b> _EFG | HIJ | KLM | WER <b> _E3R (Apply Changes)... (3 Replies)
Discussion started by: subhotech
3 Replies

9. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

10. Shell Programming and Scripting

Perl/Sed script help

Hi All, I would need to generate Oracle Inster scripts from an excel formatted spreadsheet as follows: This needs to be stripped as follows: REC 1, REC 2 etc are the separators of the records ... I beleive a pearl script can be written for this ... anything useful will be of... (8 Replies)
Discussion started by: sabyasm
8 Replies
Login or Register to Ask a Question