Finding/replacing strings in some files based on a file

Hi,

We have a file (e.g. a .csv file, but could be any other format), with 2 columns: the old value and the new value. We need to modify all the files within the current directory (including subdirectories), so find and replace the contents found in the first column within the file, with the contents of the 2nd column

e.g. the file can contain:

COL1 -- COL2
old_one new_one

So for all .sql files, i want to replace the string 'old_one' with 'new_one'.
Is it possible this? If so, how?

Thanks!

Try this...

ls -l *.csv | awk '{print $9}' > csvfiles.txt
cat csvfiles.txt  | while read LINE
do
   sed 's/oldstring/newstring/g' $LINE > $LINE.txt
   mv $LINE.txt $LINE
done

But what's that $LINE.TXT? I did not want to create another file, but in the original file to replace what's in the first column, with the content of the second one
I have only one csv, so what this does?
ls -l *.csv
My csv file is examples.csv

---------- Post updated at 11:46 PM ---------- Previous update was at 02:17 PM ----------

any help, please? regarding to previous post

---------- Post updated 12-07-12 at 07:46 AM ---------- Previous update was 11-07-12 at 11:46 PM ----------

Also, who is oldstring / newstring?

What does ur examples.csv contain?

You just want to replace "old_one" with "new_one" in that csv file alone or all of the sql files?

oldstring/newstring means oldstring could be anything that you want to replace. And newstring is the string that you want the older one to be replaced with :slight_smile:

My csv looks like in attachament. I want to replace what i found in the first column with the second one.. that's why i asked how should be specified this in that script, the content of the first column, and the one of the second one.

So, you want to replace

raise_application_error(-20100, 'An error!'); => new_string1
raise_application_error(-20100, 'Another error!'); => new_string2

right?

Exactly, in all .sql files within the current directory (and subdirectories), where i find
raise_application_error(-20100, 'An error!');it should be replaced with new_string1,

similar with the second line , and so on... i can have many lines in that file.
Thanks!

---------- Post updated at 02:03 PM ---------- Previous update was at 09:00 AM ----------

any help, please?

I'm sorry to grab the topic out but i really I need your help. I wanted to post a question in the forum but i am only like 15 minutes new user here. Here is the problem.

I have a script that has been running in my local account since 2011 with no problems.
Then few days back my whole script folder was missing. Our IT advised me it cannot
be restored so I tried to restore my backup and it was successful.

With the accidental removal I asked them to have the script and cronjob owned and executed by the root so that the folder and files are protected from any deletion ( Im using common account).

OK here is the problem. The IT brought the script to their account and cronjob also with
no problems. The next day, other users were complaining they have missing files in their login accounts.

IT blamed the culprit: Cronjob execution of my script caused the missing files from other folders and accounts.

My Home Account : MSLP1

Others (MSLP2/MSLP3/MSLP4) I have no access.

Here is the code. header Pls. help me review and tell myself that what I did was to specifically delete a file from a specific folder. I was hoping that I did not cause the files to get deleted from other accounts or folders as what our IT have advised.

variable declarations:

set scr = /export/home1/MSLP1/engg_data/SDCHECK
set tmp = $scr/temp

Code that caused the deletion when ran in root account.

find $tmp/tmpver -mtime +1 -exec rm -f {} \; >& /dev/null

Where: tmpver is a textfile I wanted to validate and delet if older than 1 day.

I really hope you can reply to me so I can sleep properly not thinking I caused trouble to my work.

This has nothing to do with this topic and you should open a sepparate topic for your question.
However, i'm waiting for help for my previous post.

Thanks

list the file
capture 2nd column

---------- Post updated at 11:00 AM ---------- Previous update was at 10:57 AM ----------

then replace it to first column