Query for replacing a string and keeping the non-replaced content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Query for replacing a string and keeping the non-replaced content
# 1  
Old 10-25-2010
Query for replacing a string and keeping the non-replaced content

Hi experts,

As i am a novice unix player...so need help for the below query...banged my head from quite a while...Smilie

i have a set of html files, in which i need to search for string "Page"(case sensitive) and then replace the same with some numeric code ,say, "XXX1234".
Here in html files, there are some other similar strings like totalPage,currentPage,etc ....


i have tried using grap and using sed command, but problem here using grap is that it will return single line containing "Page" and then i can use sed to replace that word, but along with that i need non-replaced content as it is, and final output should be html file with only desired pattern replaced.

Was thinking , if any solution is there other than formal looping constructs.

would be a great help.....Smilie
Image
# 2  
Old 10-25-2010
please give a sample of input file and output expected
Waiting for more info, here is a piece of hazardous code ..
Code:
sed 's|\(.*[ </]\)Page\([ >].*\)|\1XXX1234\2|g' input >output

To be tryied ?

Last edited by ctsgnb; 10-25-2010 at 04:06 PM..
# 3  
Old 10-25-2010
sed:
Code:
sed 's/\(^\|[^[:alnum:]_]\)Page\([^[:alnum:]_]\|$\)/\1XXX1234\2/g' infile

GNU sed:
Code:
sed 's/\bPage\b/XXX1234/g' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with compare 2 column content and corrected/replaced word

Input File CGGCGCCTCGCNNNCGAGCG CGGCGCGCCGAATCCGTGCG TCGCNGC GCGCCGC ACGGCNNNNN ACGGCCTCGCG CGGCNGCCCGCCC CGGCGCGCCGTCC Desired Output File CGGCGCCTCGCNNNCGAGCG CGGCGCGCCGAATCCGTGCG CGGCGCCTCGCATCCGAGCG TCGCNGC GCGCCGC TCGCCGC ACGGCNNNNN ACGGCCTCGCG ACGGCTCGCG... (6 Replies)
Discussion started by: perl_beginner
6 Replies

2. Programming

Best Method For Query Content In Large JSON Files

I wanted to know what is the best way to query json formatted files for content? Ex. Data https://usn.ubuntu.com/usn-db/database-all.json.bz2 When looking at keys as in: import json json_data = json.load(open('database-all.json')) for keys in json_data.iterkeys(): print 'Keys--> {}... (0 Replies)
Discussion started by: metallica1973
0 Replies

3. Shell Programming and Scripting

Replacing partial content of a file.

Hi All, Please help me in the below issue.I had a file called env.prop.In that i need to change service.url.If i select chocie 2. it should come as https://dev2.ecif.info53.com:30102/soap/default 30102 port is not fixed .It varies when the file is updated.So i want to keep orginal port in... (3 Replies)
Discussion started by: bhas85
3 Replies

4. Shell Programming and Scripting

Multiple search strings replaced with single string

Hi, I need someone's help in writing correct perl code. I implemented following code for "multiple search strings replaced with single string". ========================================================= #!/usr/bin/perl my $searchStr = 'register_inst\.write_t\(' |... (2 Replies)
Discussion started by: chettyravi
2 Replies

5. Shell Programming and Scripting

Pattern Matching & replacing of content in file1 with file2

I have file 1 & file 2 with content mentioned below. I want to get the output as shown in file3. Requirement: check the content of column 1 & column 2, if value of column 1 in file1 matches with first column of file2 then remaining columns(2&3) of file2 should get replaced, also if value of... (4 Replies)
Discussion started by: siramitsharma
4 Replies

6. Shell Programming and Scripting

Ksh Searching for a string within a file and keeping a count= get the following Sample01=: command

I have a script that goes through a 24 hr logfile, And i want to count the instances of a Test01 to 83 and output the sum of all the instances over 24hrs #/bin/ksh cat $parse_data | awk '/'$time$i'/ {for(x=0; x<=16; x++) {getline; print}print "--" }' > _hr.txt for... (2 Replies)
Discussion started by: k00061804
2 Replies

7. Shell Programming and Scripting

Replacing content from a list

Okay, so I am not quite sure the best way of going about this. I have a whole stack of files that need items replaced with a code corresponding to it. In particular, I am looking to replace the names of countries with the two letter iso country code. The files themselves are in csv format with... (4 Replies)
Discussion started by: johnlee
4 Replies

8. Shell Programming and Scripting

Performing a calculation on string to be replaced

Hi, I have a file with occurances of the string "TO_DATE(<number here>,'J')" at random places. I need minus 2400000 from the number and replace the string with "convert(date, dateadd(dd, <new number here>,'16 Nov 1858')". I'm finding this difficult as the string isn't necessarily in the... (9 Replies)
Discussion started by: user_invalid
9 Replies

9. Shell Programming and Scripting

Keeping " in string variable

Hi again, in my bash script I have several variable strings like in an array STRING_NAME="qqq qqq qqq" STRING_NAME="www www www" STRING_NAME="eee eee eee" This strings are passed to another program as ${STRING_NAME} The problem is the program doesn't recognize the whole string "qqq... (2 Replies)
Discussion started by: f_o_555
2 Replies

10. Shell Programming and Scripting

Replacing a paragraph between pattern , with the content 4m another file

hi, i wanted to put the output of file f1 into the pattern space of file f2 f1: wjwjwjwjwjwjwj //these line go in file f2 jwjwjwjwjwjjwjw wjwjwjwjjwjwjwj f2: Pattern_start __________ //these are the line to be replaced __________ Pattern_end i m... (4 Replies)
Discussion started by: go4desperado
4 Replies
Login or Register to Ask a Question