I need a little help with a shell script. I want to be able to specify parameters so that the script searches multiple files (specified as parameters) and only modifies the file if it finds the string of text. For the files it doesn't find the string of text within, it should leave it alone.
So far, it seems like it only checks the first file and if that one is "true", it creates a .bak file for the remaining files (or vice versa if the first text file comes back as "false". It is replacing the text in all text files specified, but it is creating the .bak files when it is not necessary.
As an example, If i have four text files: text1.txt, text2.txt, text3.txt text4.txt, I would want to have the script look through each file, see if the string of text exists and then replace the string only if it exists, such as:
The files to be replaced aren't necessarily .txt files. For example, one time running the script, I may want to replace a variety of .txt and .dat files, another time I may want to only want to replace .dat files or .txt files, etc.
The code I have now does replace the text successfully in all the files I specify. However, I want the files to not be touched/modified if grep does not find the string of text in the file.
---------- Post updated at 01:54 AM ---------- Previous update was at 01:37 AM ----------
I figured out what I was doing wrong. The $SEARCH variable shouldn't have been set as a global variable. It should have been within the "if" loop, such as:
Last edited by Franklin52; 02-20-2010 at 07:43 AM..
Reason: Please use code tags!!
Good Evening Folks -
Happy Friday!
I have a need to replace a certain string in all .csv files from "0.00" to "#Missing" in my /app/hyp_app/files directory.
Does anyone have a script they use regularly that's rather quick in performance? My files are rather large so I'm looking for a... (5 Replies)
Hello,
I'm an starter in Bash scripting. I would like to write a script in Bash shell that replaces a specific text block (a function) by another text block in a file:
for example in my file --> $HOME/myFile.js
replacing following function between other functions in the file:
function ABC()... (6 Replies)
Hi,
I am looking for assistance over shell or perl (without XML twig module) which replace string in XML file under particular branch..example of code file sample..
Exact requirment : Replace "Su saldo es" in below file with "Your balance" but only in XML branch of Text id=98 and Text Id=12... (7 Replies)
Hi all
I have data files which contain data as shown below:
Line 5: FIDE
INST_DESC: DIAM Co Ltd/Japan => MAID Co Ltd/Japan
INST_NME: DIAM Co Ltd/Japan => MAID Co Ltd/Japan
Line 6: FIDE
INST_DESC: DIAM DL/Pimco US Bond Open Born in the USA => MAID DL/Pimco US Bond Open Born in the... (6 Replies)
Hi Folks,
I have an html file which contains the below line in the body tagI am trying the replace hello with Hello Giridhar programatically.
<body>
<P><STRONG><FONT face="comic sans ms,cursive,sans-serif"><EM>Hello</EM></FONT></STRONG></P>
</body>
I have written the below code to... (3 Replies)
Hi
I am new to unix and newbie to this forum. I need help in writing a gawk script that search and replace particular text in a flat file.
Input file text :
ZIDE_CONTROL000 100000000003869920900000300000001ISYNC 000002225489 0000000002232122 20120321 16:40:53
ZIDE_RECORD000... (5 Replies)
Can I just say, this is such a frustrating and yet enormously rewarding field of study. I'm in the middle of configuring GeekTool (Uh oh, stupid n00b) and I really only have one question.
I'm using Automator to grab a RSS feed, having GeekTool continually run that application every 10 minutes,... (7 Replies)
I have a file something like this (except much larger amount of rows/data)
0001 blue testing1
0002 blue testing2
0006 blue testing3
0232 red testing4
2143 blue testing5
3453 blue testing6
In a script I want to replace the word red with blue where the line begins with a... (4 Replies)
hai everybody,
i am new to scripting,i have to replace a value with another value ina script...both the values i have got in two seperate variables...can anyone give me the syntax how to do this in a shell script...
ie.
e1=$5,e2=$6
v2=$1,v3=$7
now i want to... (2 Replies)