The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Multi File processing orahi001 Shell Programming and Scripting 2 01-10-2008 04:49 PM
How to redirect std err and out to log file for multi-commands? siegfried Shell Programming and Scripting 1 08-10-2007 09:43 PM
multi file editing in vi ricl999 Shell Programming and Scripting 0 04-21-2006 08:23 AM
Multi User Multi Task Reza Nazarian UNIX for Dummies Questions & Answers 6 04-13-2006 10:23 AM
Multi booting file systems onestepto Windows & DOS: Issues & Discussions 2 11-10-2002 01:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 2 votes, 4.50 average. Display Modes
  #1 (permalink)  
Old 06-26-2001
kielitaide
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Question multi-file multi-edit

Good day!

I am trying to learn how to use the "sed" editor, to perform multiple edits on multiple files in multiple directories.

I have one script that tries to call up each file and process it according to the edits listed in a second script. I am using a small input text to test these, at this point. I show both scripts and the input text below.

(a) I am not sure that I am using the "find" command effectively, to find all the files that will be nested in various directories. They will all be *.tex files.

(b) I am certainly not using sed correctly -- help?

If anyone can help me forward on either of these issues, I'll be very grateful!

Kielitaide
------------------------------------------------------------------------
find.sh
-------------
#!/bin/sh

for file in 'find *.txt'
do
mv $file $file.sed
./edit.sh $file.sed > $file
rm $file.sed
done
------------------------------------------------------------------------
edit.sh
---------
#!/bin/sh

sed -e s/e/I/g $1
sed -e s/a/E/g $1
------------------------------------------------------------------------
abc.txt
---------
apple

banana

cherry
------------------------------------------------------------------------
  #2 (permalink)  
Old 06-26-2001
alwayslearningunix
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
You forgot to specify a path and operator for find to search, try this in your for loop:

`find /directory/to/search -name *.txt`

Your sed statements seems okay to me, if what you are trying to do is globally substitute e for I and a for E in the files you are finding.

Hope this helps, if not ask again!

Regards

  #3 (permalink)  
Old 06-26-2001
kielitaide
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Smile

Thank you very much

I have about 400 .tex files nested in a number of sub...directories, within about 20 subdirectories, within one directory.

How should I tell "find" to look into all those subdirectories etc. to find all the *.tex files?

Now my find.sh says:

#!/bin/sh

for file in 'find ./ -name *.txt'
do
mv $file $file.sed
./edit.sh $file.sed > $file
rm $file.sed
done

The name of the draft is now "input.txt", and the errors I receive are:

mv: invalid option -- n
Try 'mv --help' for more information.
-/find.sh: $file ambiguous redirect
rm: invalid option -- n
Try 'rm --help' for more information.

Thanks and best wishes!
K
  #4 (permalink)  
Old 06-26-2001
alwayslearningunix
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Find will search recursively down from the path that you specify, but you may want to change the syntax of your find command in your for loop to:

`find /path/to/search -name "*".txt`

This will search recursively down that path to find all *.txt files, and find should not complain of a missing conjunction

Hope this helps.

Regards.
  #5 (permalink)  
Old 06-26-2001
kielitaide
Guest
  
 

Posts: n/a
Bits: 0 [Banking]


It is very kind of you to take the time to help me.

Unfortunately, when I added the " double quotes around the asterisk "*", nothing changed -- I got the same error messages.

oooo
ooooo <-- K sends cookies
oooo
  #6 (permalink)  
Old 06-26-2001
mib mib is offline
Registered User
  
 

Join Date: Jan 2001
Location: Calicut
Posts: 228
#!/bin/sh

for file in `find . -name "*.txt"`
do

perl -pi.bak -e 's/e/I/g; s/akE/g;' $file

#mv $file $file.sed
# sed -e 's/e/I/g;s/a/E/g' $file.sed > $file
done


in Perl method it will first backup the file with '.bak' then edit it in place.


HTH


  #7 (permalink)  
Old 06-26-2001
kielitaide
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Cool

Hi there

Now I have multi-file.sh:

#!/bin/sh
for file in 'find . -name "*.txt"'
do
perl -pi.bak -e 's/e/I/g; s/a/E/g;' $file
done

And I have a text file "input.txt":

apple
banana
cherry

And error messages:

Can't open find: No such file or directory
Can't do inplace edit: . is not a regular file.
Can't open -name: No such file or directory
Can't open "*.txt": No such file or directory



K
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0