Sponsored Content
Top Forums Shell Programming and Scripting Help with Regexp replace in vim/sed Post 302488290 by durden_tyler on Sunday 16th of January 2011 01:55:38 PM
Old 01-16-2011
If Perl is an option, then :

Code:
$
$
$ cat f2
<a href="xxx.aaa_bbb_ccc.yyy">xxx.aaa_bbb_ccc.yyy</a>
<a href="xxx.aaa_bbb_ccc.yyy">xxx.aaa_bbb_ccc.yyy</a>
<a href="xxx.aaa_bbb_ccc.yyy">xxx.aaa_bbb_ccc.yyy</a>
<a href="xxx.aaa_bbb_ccc.yyy">xxx.aaa_bbb_ccc.yyy</a>
<a href="xxx.aaa_bbb_ccc.yyy">xxx.aaa_bbb_ccc.yyy</a>
$
$
$ perl -lne '($x,$y,$z)=/^(.*">)xxx.(.*).yyy(.*)$/; $y=~s/_/ /g; $y=ucfirst $y; print "$x$y$z"' f2
<a href="xxx.aaa_bbb_ccc.yyy">Aaa bbb ccc</a>
<a href="xxx.aaa_bbb_ccc.yyy">Aaa bbb ccc</a>
<a href="xxx.aaa_bbb_ccc.yyy">Aaa bbb ccc</a>
<a href="xxx.aaa_bbb_ccc.yyy">Aaa bbb ccc</a>
<a href="xxx.aaa_bbb_ccc.yyy">Aaa bbb ccc</a>
$
$

tyler_durden

Last edited by durden_tyler; 01-16-2011 at 03:01 PM..
This User Gave Thanks to durden_tyler For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

regexp with sed again!!!

please help: I want to add 1 space between string and numbers: input file: abcd12345 output file: abcd 1234 The following sed command does not work: sed 's/\(+\)\(+\)/\1 \2/' file Any ideas, please Andy (2 Replies)
Discussion started by: andy2000
2 Replies

2. Shell Programming and Scripting

Replace Entire line if any part matches regexp

Hey guys, I have a file that I've slowly been awking, seding, and greping for data entry. I am down to pull the addresses out to insert them into an excel file. Each address is a few lines, but i want to put a semicolon delimiter in between each address so I can export the text file into excel and... (6 Replies)
Discussion started by: Cocoabean
6 Replies

3. UNIX and Linux Applications

vi or vim replace ,$ (eol) with just a comma

I have lines in a file like this (140,000+ entries): value1, value2, value3, " " I want to concatenate the three (there are 22) lines with commas so it looks like this value1, value2, value3 " " I'm trying with :g/,$/s/,$/, /g but that is not flying. any ideas? (6 Replies)
Discussion started by: dbauhaus
6 Replies

4. UNIX for Dummies Questions & Answers

VIM: replace a character in the middle of line

exmaple, i need to replace the number "5" from all lines below with "X"? What is the useful vim command that i can apply for.. ddpadsgg506xghssuyj ddpadsgag546xghssuys ddsadsgaag596xghssuy_te ddsadsgag506xghssuy_pe ddsadsgagc526xghssuys ddsads506ighssuys ddsadsgag506pghssuyk (1 Reply)
Discussion started by: 793589
1 Replies

5. Shell Programming and Scripting

sed regexp

Hi, I am not that good with reg exp and sed. But I was just looking at something the other day and came across a situation. When I ran the below command: echo "123 word" | sed 's/*/(&)/' the op was: (123) word But when I ran: echo "123 word" | sed 's/*/(&)/g' the o/p was: (123)... (4 Replies)
Discussion started by: King Nothing
4 Replies

6. UNIX for Dummies Questions & Answers

sed before and after regexp

Dear all i have the code which print 1 line of context before and after regexp, with line number sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h the code work well but any one can tell me what each letter mean {=;x;1!p;g;$!N;p;D;} also how i can print 2 line before and onle line after ... (2 Replies)
Discussion started by: soly
2 Replies

7. Shell Programming and Scripting

Advanced AWK Regexp substring to int & Replace

Hi! I have a difficult problem, to step up a unknown version number in a text file, and save the file. It would be great to run script.sh and the version gets increased. Example the content of the textfile.txt hello version = x bye This include three steps 1. First find the char after... (2 Replies)
Discussion started by: Beachboy72
2 Replies

8. Shell Programming and Scripting

replace awk with a perl one liner (REGEXP and FS)

hello, I want to replace awk with a perl one liner in unix. i use in awk REGEX and FS ( field separator) because awk syntaxes in different unix os versions have not the same behaviour. Awk, Nawk and GNU Awk Cheat Sheet - good coders code, great reuse i have a file named "file" and want... (5 Replies)
Discussion started by: bora99
5 Replies

9. Shell Programming and Scripting

Need help with sed and regexp

Hi everyone, I would really appreciate any help I could get on the following topic. I am not very familiar with reg expressions nor with sed, I just know the basic uses. What I am trying to do is the following: I have a huge text file where I would like to replace all occurnces of a certain... (13 Replies)
Discussion started by: Boxtuna
13 Replies

10. Shell Programming and Scripting

find and Replace String in Perl - Regexp

Trying to find and replace one string with another string in a file #!/usr/bin/perl $csd_table_path = "/file.ntab"; $find_str = '--bundle_type=021'; $repl_str = '--bundle_type=021 --target=/dev/disk1s2'; if( system("/usr/bin/perl -p -i -e 's/$find_str/$repl_str/' $csd_table_path")... (2 Replies)
Discussion started by: cillmor
2 Replies
All times are GMT -4. The time now is 06:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy