Sponsored Content
Full Discussion: Bulk Find and Replace
Top Forums Shell Programming and Scripting Bulk Find and Replace Post 302677639 by Vryali on Thursday 26th of July 2012 12:11:33 PM
Old 07-26-2012
Lots of whats to do this, but simply done like this:

Code:
$ cat *.html | sed 's/\(.*taskid=\)\([0-9]*\)\(.*$\)/\133528\3/g' 
http://unix.com/cgi-bin/task?taskid=33528&task.out
http://unix.com/cgi-bin/task?taskid=33528&task.out
http://unix.com/cgi-bin/task?taskid=33528&task.out
http://unix.com/cgi-bin/task?taskid=33528&task.out

So in a find statement:
Code:
for file in $(find /dir -name '*.html' -print); do
    sed 's/\(.*taskid=\)\([0-9]*\)\(.*$\)/\133528\3/g' ${file} > /tmp/tmp.file
    mv /tmp/tmp.file ${file}
    # If needed to fix permissions and ownership
    chmod XXX ${file}
    chown X:X ${file}
done

Edit:

You were close on your sed statement, here's what you probably were going for that route:
Code:
$ cat *.html | sed 's/taskid=[0-9]*/taskid=123456/g'
http://unix.com/cgi-bin/task?taskid=123456&task.out
http://unix.com/cgi-bin/task?taskid=123456&task.out
http://unix.com/cgi-bin/task?taskid=123456&task.out
http://unix.com/cgi-bin/task?taskid=123456&task.out


Last edited by Vryali; 07-27-2012 at 02:51 PM..
This User Gave Thanks to Vryali For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

find and replace

I have a file that I want to remove all of the periods from. I am using the below to remove quotations and it works fine -I thought I could make it work for the period but it does not. Any help would be appreciated. works to remove the double quote mark (") sed -e 's/"//g' input file... (4 Replies)
Discussion started by: valhutch
4 Replies

2. UNIX for Dummies Questions & Answers

find and replace

I have statement like this column_id.columnname=="value" in unix i want to modify above statement to variable1=="value" that means i have to replace the string before "==" by string "variable1" second catch is, in statement instead of "==" you can have any arithmatic comarision... (7 Replies)
Discussion started by: mahabunta
7 Replies

3. UNIX for Advanced & Expert Users

Please help with find and replace:

Hi I am trying to find a product code hightlighted in red, and re-insert it at another place on the same file. I shall be grateful if anyone can help me with this. Stuck and have deadline!!:confused: Original Line: (I can get source data in one of these two formats) ISD=977155185403901+DIE... (2 Replies)
Discussion started by: gloovy_tb
2 Replies

4. Shell Programming and Scripting

find and replace

Hi, There are some "n" files in a directory which contains comman string.A command to find and replace the string in all the files without looping. like if i am in a directory : # find ./ -name ".txt" | xargs sed -e 's/test/tst' Upto here is performed correctly and i want to... (4 Replies)
Discussion started by: rakshit
4 Replies

5. Shell Programming and Scripting

find replace

Hi I am replacing some string occurances with empty string in all files under one directory using find ./ -name "*.dmp" | xargs perl -pi -e 's/\\N//g' | its taking too much time for replacing and redirecting to same file in the same directory. Similarly afterwards i am finding last... (2 Replies)
Discussion started by: dbsurf
2 Replies

6. UNIX for Dummies Questions & Answers

Find and Replace

After running a command like grep -ir files2/ * This will find all the files that contain "files2/" in it. For example if it finds files2/dir/today files2/dir/yesterday files2/dir/2daysago Now it may find 100 instances, so is there a quick find and replace command I can use? I... (4 Replies)
Discussion started by: NycUnxer
4 Replies

7. Shell Programming and Scripting

find and replace

Hi I am very new to shell scripting (and linux in general)... I am trying to build some script, that will read a person from a csv file, (each person will have an ID, eg id001abc, which will go up one by one a few hundred times) then when find and replace the matching data in an xml file. ... (4 Replies)
Discussion started by: sam.breslin
4 Replies

8. Shell Programming and Scripting

Shell or perl script to replace XML text in bulk

Hi, I am looking for assistance over shell or perl (without XML twig module) which replace string in XML file under particular branch..example of code file sample.. Exact requirment : Replace "Su saldo es" in below file with "Your balance" but only in XML branch of Text id=98 and Text Id=12... (7 Replies)
Discussion started by: Ashu_099
7 Replies

9. Shell Programming and Scripting

Bulk find in UNIX at unknown dir location

Dear All, I have a file which is having a number my_file.csv 032001031 100509001 203001165 there are many more about 5000. I have a path in unix /my_path/my_loc/DEV/RPD10/CPD25/WFM/RK_WFM/OUT/*/ where i will have a file like CPD25_203001165.pdf CPD25_100509001.pdf... (4 Replies)
Discussion started by: yadavricky
4 Replies

10. Shell Programming and Scripting

Find and replace

Hi Team, one silly issue. but its not working for me. I need to find a pattern a file and replace it with the given value in another file. Here's the code snippet. Search_String=100 Replace_String=151 cat ${work}/temp_${CSV_File} | sed 's|"${Search_String}"|"${Replace_String}"|g'... (2 Replies)
Discussion started by: kmanivan82
2 Replies
HLINS(1)						      General Commands Manual							  HLINS(1)

NAME
hlins - insert url's into html documents SYNOPSIS
hlins [options] [infile] DESCRIPTION
hlins is a program that inserts hypertext links into html documents, according to one or several data bases associating addresses (url's) to names. hlins is designed for inserting links for persons: It knows about abbreviations of first and middle names and tolerated dropping of the last part of a composite last name. If no file argument is given then input is taken from stdin; when no output option (see below) is given then output goes to stdout. For a complete description, see the documention in html format. OPTIONS
hlins follows the usual GNU command line syntax, with long options starting with two dashes (`--'). -o, --output-file file Write to file instead of standard output -h, --help Show a summary of options. -v, --version Show the version of the program. -q, --quiet Surpress diagnostic output. -db, --data-bases files ... Use files ... as data bases -m, --modify files ... Dont't act as filter but perform in-pace modifications of files. -R, --recursive Recursively descend into directories and act on all files with names ending on .html. -td, --tmp-dir dir Use directory dir to create temporary files. --db-to-html List the address data bases in HTML format to stdout. ENVIRONMENT
TMPDIR default directory for creating temporay files. VERSION
This manual pages describes version 0.39. SEE ALSO
The full documentation with examples should be available in /usr/share/doc/hlins/. See also the hlins home page http://www.lsv.ens-cachan.fr/~treinen/hlins/. AUTHOR
Ralf Treinen <treinen@debian.org>. July 25, 2000 HLINS(1)
All times are GMT -4. The time now is 07:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy