There are a few problems here. If this script is in the directory where you are looking for and changing occurrences of "./x.mak", one of the files it will try to modify is itself (in at least two places).
Second, in standards conforming versions of sed, \n in the replacement string of a substitute command will insert an <n> character, not a <newline> character. I know that some versions of sed do provide the common backslash escapes here, but using them here might or might not work depending on what OS (or sed utility) you're using. In a standards conforming sed, you could use a backslash-escaped literal newline character instead of the \n to get what you want:
Third, the -print0 primary in find is also an extension to the standards. If the system you're using supports it and you're going to use xargs as well as find -print0 you have to also use the xargs -0 option when you invoke xargs. If you wanted a more portable way to do this you could try:
And finally, the script you provided seems to try to print the contents of all of the regular files it finds in and under the current directory (with changes to any occurrence of "./x.mak") to standard output, but does not save any of the changes into any of the source files. I would guess this isn't what you're trying to do. (If this really is what you want, you could also change the \; at the end of the find -exec primary's arguments in the last suggestion above to + to run more efficiently.)
If you do want to actually change the contents of the files containing "./x.mak" (and only them), you are absolutely certain that no filename components in the file hierarchy you'll be processing contain a <newline> character, and you only want to change files in the current directory or a known list of directories (not those in all subdirectories recursively); you might consider a loop like:
where I would expect processing would exclude your script and actually change the contents of other files that contained the target string. Note that grep -F matches fixed strings (not regular expressions) so the periods don't need to be escaped here. (Note also that some versions of grep provide a recursive option (-R) that could be used as:
to process all files in and under the current directory containing the target string.)
Hope this helps.
This User Gave Thanks to Don Cragun For This Post:
I want to use sed to check if a short line is contained in the line after it, and if it is, to delete the short one. In other words, the input is...
This is a
This is a line
... and I want it to give me...
This is a line
Here's what I've tried so far: s/\(^.*\)\n\(\1.*$\)/\2/
Also,... (7 Replies)
Can someone tell me how I can do this?
e.g:
Say file1.txt contains:
today is monday
the 22 of
NOVEMBER
2010
and file2.txt contains:
the
11th
month
of
How do i replace the word NOVEMBER with (5 Replies)
i have few lines in a file... i am reading them in a while loop so a particular line is held is $line1.. consider a modified line is held in $line2.... i want to replace $line1 with $line2 in the same file... how to do it..?
i have come up till the below code
sed "s/$line1/$line2/g" tmpfile.sql... (5 Replies)
I am trying to find a line in a file ("Replace_Flag") and replace it with a variable which hold a multi lined file.
myVar=`cat myfile`
sed -e 's/Replace_Flag/'$myVar'/' /pathto/test.file
myfile:
cat
dog
boy
girl
mouse
house
test.file:
football
hockey
Replace_Flag
baseball
... (4 Replies)
Hi How Are you?
I am doing fine!
I need to go now?
I will see you tomorrow!
Basically I need to replace the entire line containing "doing" with a blank line:
I need to the following output:
Hi How Are you?
I need to go now?
I will see you tomorrow!
Thanks in advance.... (1 Reply)
my requirement is,
consider a file output
cat output
blah sdjfhjkd jsdfhjksdh
sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf
hellow there
this doesnt look good
et cetc etc
etcetera
i want to replace a line of line number 4 ("this doesnt look good") with some other line
... (3 Replies)
All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed...
I have an input file similar to:
&LOG
&LOG Part: "@DB/TC10000021855/--F"
&LOG
&LOG
&LOG Part: "@DB/TC10000021852/--F"
&LOG Cloning_Action: RETAIN
&LOG Part: "@DB/TCCP000010713/--A"
&LOG
&LOG... (5 Replies)
Sed command to replace a line in a file using line number from the output of a pipe.
Is it possible to replace a whole line piped from someother command into a file at paritcular line...
here is some basic execution flow..
the line number is 412
lineNo=412
Now i have a line... (1 Reply)
Hi all,
Let's say I have a script calling for the two variables PA_VALUE and PB_VALUE.
for pa in PA_VALUE
blah blah
do
for pb in PB_VALUE
blah blah
do
I have a text file with two columns of values for PA and PB.
14.5 16.7
7.8 9.5
5.6 3.6
etc etc
I would like to read this... (7 Replies)