string replace in huge file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting string replace in huge file
# 1  
Old 07-16-2012
string replace in huge file

I need to parse a huge file... with some strings like this:

<li class="website-feature"><a href="http://some.changingurl.com" ..(some changing classes)..>

I need to change the above to:

<li class="website-feature">http://some.changingurl.com<a href="http://some.changingurl.com" ..(some changing classes)..>

Then later on I can remove all html tags but keep the url saved. Only the url is changing.

Please help me write a subsititution.

Thank you.

---------- Post updated at 07:25 PM ---------- Previous update was at 05:14 PM ----------

anybody help?

Last edited by dtdt; 07-16-2012 at 08:25 PM..
# 2  
Old 07-16-2012
Have a go with this. It works for me on the limited example you provided, but it might over match with other lines. It only replaces the first one on each line; if there are multiple sets that need to be replaced it will need at least a small tweak if not more effort.

Code:
sed -r 's/<a href="([^["]*)"/\1&/' input-file >new-file

If you are using sed on a BSD machine, or using the sed which is a part of the AT&T AST tools, then use -E instead of -r.
# 3  
Old 07-17-2012
Thanks a lot. I am testing it.

Quote:
Originally Posted by agama
Have a go with this. It works for me on the limited example you provided, but it might over match with other lines. It only replaces the first one on each line; if there are multiple sets that need to be replaced it will need at least a small tweak if not more effort.

Code:
sed -r 's/<a href="([^["]*)"/\1&/' input-file >new-file

If you are using sed on a BSD machine, or using the sed which is a part of the AT&T AST tools, then use -E instead of -r.
---------- Post updated 07-17-12 at 02:38 PM ---------- Previous update was 07-16-12 at 09:30 PM ----------

it works! ty
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search partial string in a file and replace the string - UNIX

I have the below string which i need to compare with a file and replace this string in the file which matches closely. Can anyone help me on this. string(Scenario 1)- user::r--,user::ourfrd:r-- String(Scenario 2)- user::r-- File **** # file: /local/Desktop/myfile # owner: me # group:... (6 Replies)
Discussion started by: sarathy_a35
6 Replies

2. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies

3. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

4. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

5. UNIX for Dummies Questions & Answers

Need to replace new line characters in a huge file

Hi , I would like to replace new line characters(\n) in a huge file of about 2 million records . I tried this one (:%s/\n//g) but it's hanging there and no result. Does this command do not work if the file is big. Please let me know if you have any other options Regards Raj (1 Reply)
Discussion started by: rajeevm
1 Replies

6. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

7. Shell Programming and Scripting

Optimised way for search & replace a value on one line in a very huge file (File Size is 24 GB).

Hi Experts, I had to edit (a particular value) in header line of a very huge file so for that i wanted to search & replace a particular value on a file which was of 24 GB in Size. I managed to do it but it took long time to complete. Can anyone please tell me how can we do it in a optimised... (7 Replies)
Discussion started by: manishkomar007
7 Replies

8. Shell Programming and Scripting

search a string in a huge file

How to search a string which has occured numerous times in a single row. I tried many options, I am facing issue with the file size. Anything I go for, it says it is huge.. File is 82MB. Assume, the file contains the string 'Name' in many places.. Something Like below. ... (5 Replies)
Discussion started by: Muthuraj K
5 Replies

9. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

10. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies
Login or Register to Ask a Question