|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Running sed scripts on multiple files??
Please excuse my lack of knowledge but I am wondering if there is a way to run a sed script on multiple files. My script is basic and I am used to running it on one file at a time but I have hundreds of files.
I normally use the command: sed -f scriptname.txt filename.sgm > filename.sgm My files are not text files (sgml files) and my sed script looks like this: 1,$s/rg="A-0000000034"/rg="A-055101010"/g 1,$s/rg="A-0000000035"/rg="A-055104010"/g 1,$s/rg="A-0000000036"/rg="A-055107010"/g 1,$s/rg="A-0000000037"/rg="A-055108010"/g 1,$s/rg="A-0000000038"/rg="A-055114010"/g 1,$s/rg="A-0000000039"/rg="A-055115010"/g There are a few hundred lines like this. Any suggestions would be appreciated. |
|
#2
|
|||
|
|||
|
try
Code:
cd /path/to/files for file in *.sgm do sed -f scriptname.txt $file > $file done the shell will glob (expand) the * into full file names for you. You may have to adjust the '*' part to get the files you want. |
|
#3
|
|||
|
|||
|
NO !
this is wrong: sed -f scriptname.txt $file > $file but: sed -f scriptname.txt $file > tmp.$file [ -s tmp.$file ] && mv tmp.$file $file ------ in this case: 1,$s/rg="A-0000000039"/rg="A-055115010"/g and s/rg="A-0000000039"/rg="A-055115010"/g are the same, maybe you can reduce thr regexp to s/0000000039/055115010/g >>There are a few hundred lines like this. i remember sed has limit, believe 200 cmds Last edited by guggach : August 28th, 2004 at 02:10 AM. Reason: typo |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Running sed scripts on multiple files?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|