![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
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 ------------------------------------------------------------------------ |
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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. |
|
||||
|
#!/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 |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|