iterate sed over files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting iterate sed over files
# 1  
Old 07-21-2007
iterate sed over files

Greetings.

I'm having a time of it with this file. I'm trying to do a script that will take two command line inputs, string1 and string2 and use sed to change the text over files in the current directory. This is what I have so far. It appears to work a little, it does create the filechanges.txt file and string.$$ but the sed piece is not working correctly. I have tried "" and ' ' the sed statement but it still does not want to cooperate.

if [ $# -lt 2 ] ; then

echo "Usage: changeInFiles string1 string2"
exit 1
fi

find . -type f > filechanges.txt

for i in filechanges.txt

do

sed s/$1/$2/g $i >string.$$; cat string.$$ > filechanges.txt

done

rm -rf string.$$

Thanks for any help
# 2  
Old 07-21-2007
looking for something like this
Code:
a=Q13251
b=abc

echo "671320070521330000000003|Q13251|A18741|456787654328977" | sed "s/$a/$b/"

# 3  
Old 07-21-2007
I would like to iterate the sed over all the files in the current directory and replace globally string2 for string1, in all the files. Not sure if I sould be using

for i in $files

or

for file in $files

to run the grep over
# 4  
Old 07-21-2007
Code:
while read file
do
# do sed processing here or something else
done < file_with_list_of_files_to_be_processed

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Iterate over `dirs` in a bash script

I would like to iterate over `dirs`in a script, but the script will never show more than one (current) folder #! /bin/bash for i in `dirs` do echo ${i} done echo ++++++++++++++++++ for i in $( dirs -p ) do echo ${i} done echo ------------------ dirscontent=`dirs` echo... (5 Replies)
Discussion started by: alexanderb
5 Replies

2. UNIX for Beginners Questions & Answers

Script to iterate over several options

Have two 3 files which has list of servers,users and location and base url which is common on every server A = server1 server2 server3 B = user1 user2 user3 C = dom1 dom2 dom3 baseurl=/opt/SP/ and what i have to achieve is below via ssh from REMOTE SERVER for it's first iteration it... (7 Replies)
Discussion started by: abhaydas
7 Replies

3. Shell Programming and Scripting

Iterate column with perl

I can not figure out how to iterate a perl command that inputs a value into columns and then combines them. I need to put a numerical value in column one and the word "Null" in all others, and then join at the end. I think the below is close, but I am not sure about the lines in bold. I... (7 Replies)
Discussion started by: cmccabe
7 Replies

4. Shell Programming and Scripting

Iterate array using loop over ssh

A simple script: #!/bin/bash test=test test1=(test1 test2 test3) echo ${test1 } ssh server 'echo '$test'; echo '${test1 }' ; echo '${test1}' ; for m in $(seq 1 $(echo '${test1 }' | tr " " "\n" | wc -l)); do echo $m ; echo '${test1}'; done'Here is the result: test1 test2 test3 testing... (5 Replies)
Discussion started by: mharald
5 Replies

5. Shell Programming and Scripting

Do loop doesn't iterate

I'm trying to send the file list as parameter to another job and execute it. But the loop doesn't work, the inner job is running only once and not twice as expected for filelist in $(ls -rt *.txt | tail -2) do echo $filelist export filelist cmd="$Program -config $configfile -autoexec... (11 Replies)
Discussion started by: asandy1234
11 Replies

6. Shell Programming and Scripting

script to iterate

Hi i need to find x in the following equation such that it satisfies this condition: y/x-ln(x)-1.24=0 how can i write a script to iterate to give random x to satisfy this equation. y is different each time too. any help with awk/shell script will be awesome! thanks (1 Reply)
Discussion started by: saint2006
1 Replies

7. Shell Programming and Scripting

Need script to count specific word and iterate over number of files.

Hi Experts, I want to know the count of specific word in a file. I have almost 600+ files. So I want to loop thru each file and get the count of the specific word. Please help me on achieving this... Many thanks (2 Replies)
Discussion started by: elamurugu
2 Replies

8. Shell Programming and Scripting

Shell - How to iterate through all the files in a directory?

Hi, I have a directory call Test, which contains files "a", b", "c", etc. I want to go through all of the files inside Test and remove any empty file. How would I do that with shell csh? So far I got... #!/bin/csh if (($#argv == 0) || ($#argv > 1)) then echo "no argument or too... (2 Replies)
Discussion started by: teiji
2 Replies

9. Shell Programming and Scripting

iterate over array

I can not for the life of me figure out how to iterate over this array { 'name1' => { 'a' => . 'b' => }, 'name2' => { 'a' => . 'b' => } } I want a for loop to iterate through the first element (name1 and name2 in my example) but I can't figure it out. Help... (2 Replies)
Discussion started by: IMTheNachoMan
2 Replies

10. Shell Programming and Scripting

How do i iterate thru each line of a file in shell scripting?

Hi All, I need to execute some commands on each line of a file. How do i iterate thru each line of a file? In detail: First i will have to go to the first line of the file and execute a series of commands on it and then take the second line of the file, execute a series of steps and so... (2 Replies)
Discussion started by: Ravi Varma
2 Replies
Login or Register to Ask a Question