UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old August 27th, 2004, 01:42 PM
p40whk p40whk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 1 p40whk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old August 27th, 2004, 03:14 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
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.

Reply With Quote
  #3  
Old August 28th, 2004, 02:05 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 44 m 45 sec
Reputation Power: 9
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Running sed scripts on multiple files??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway