I need a command that will work on file (xml) and replace multiple occurrence (more than 2 times)
should be replaced by just '==' Note :- single character should be replaced. (= should be replaced by ==)
I have used this command:- But after using this command i found, where single character = is there, it changes into ==
Seems to me that this is what you wanted, isn't it?
If you only want to replace two or more occurences of "=" use:
You cannot direct the output of sed to the input file, because that would overwrite and destroy the input file after the first line. Therefore a different output file name.
Is there any possibility, that after editing original file, and after process completes, can we replace original with output file, Becoz i have a file of 38 Gb.
I have managed shell script, as i am doing shell scripting first time, i am trying to create a script where file should be deleted after completing the process.
I want to extend command and delete original file and name the new file created same as old one.
Ex.
-Red.
(Becoz which i am working is 38 Gb and my Server dont have much resources, right command will help me.)
Moderator's Comments:
Please use next time code tags for your code and data
Last edited by vbe; 06-22-2012 at 12:06 PM..
Reason: code tags please!
There is no other way than what you have already found out: use a different file and then move the new file over the old file.
The reason for this i have described here and in some other postings too - i don't want to repeat it.
Btw., a suggestion: stay away from GNU-seds "-i" switch: it will just make your script less portable, but will do nothing else than do the "mv"-operation automatically afterwards.
Thank you for your suggestion. I have used, Below command, where it gives output in same file.
You seem to have misunderstood what i explained. "perl -i" does the same as "sed -i": it creates a temporary second file where it stores the changes and moves this over the original file as the last step.
You gain nothing by using perl (save for a considerably slower speed of execution, because native UNIX commands are way faster).
The point is simple: to edit a file you need to be able to store 2 versions of it.*) There is no way around that. The "-i" options of various tools just blur that fact by hiding this temporary file, but it is still necessary.
If you fear a long execution time for moving the file: don't. It is in fact just a change in the files i-node (which is a few bytes) as long as the temporary file and the original file are on the same filesystem. To execute
takes the same time, regardless of the size of this file (as long as they both are on the same filesystem). So set your "TMP" or "TMPDIR" variable accordingly and have enough room on your disk - some 100GB should not really be a problem these times of multi-TB SAN storage fabrics.
I hope this helps.
bakunin
________________
*) actually this is not completely true, because there is a trick:
This will work for files which are small enough to fit into memory. The downside is, that if anything goes wrong (power loss, reboot, process aborted, ...) your data will be irrevocably destroyed. You sure do not want to use this hack on critical data just to save a few GB of (temporary) diskspace.
This will work for files which are small enough to fit into memory. The downside is, that if anything goes wrong (power loss, reboot, process aborted, ...) your data will be irrevocably destroyed. You sure do not want to use this hack on critical data just to save a few GB of (temporary) diskspace.
That won't work even when there's just a single byte in the file, if the shell first creates the sed portion of the pipeline. There are no guarantees on which component of a pipeline will be created first.
I'm trying to find out what happened to the rogue game that apt-get told me it installed, so I thought I would find the file. I went to the root and entered:
find -name "rog*.*"
I get a large number of lines saying my access is denied in various directories. I figure I'll practice my Unix... (14 Replies)
Dear Ladies & Gents,
I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out:
for filename in $(find /var/log/test... (2 Replies)
How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address
and column 3 contains “cc” e-mail address to include with same email.
Sample input file, email.txt
Below is an sample code where... (2 Replies)
Hi,
Below line selects only dates comes after than today.
I need to change below line as "more or equal":
awk -F\## -v d=$(date +%Y%m%d) '{if($NF>d)print}' /usr/batch/pill.txt > /usr/batch/pill_in_use.txt
When we change the code, it will print today's date and following dates only.
... (2 Replies)
I want to list all files/lines which except those which contain the pattern ' /proc/' OR ' /sys/' (mind the leading blank).
In a first approach I coded:
find / -exec ls -ld {} | grep -v ' /proc/| /sys/' \; > /tmp/list.txt
But this doesn't work. I got an error (under Ubuntu):
grep:... (5 Replies)
Hi all,
I have this text file containing 9 columns separated by space. The 8th columns contains the numbers.
C1 C2 C3 C4 C5 C6 C7 C8 C9
er rt yt gh iu nk il 0.07 xs
yt lr ty bg iu zk nh 0,0005 lt
...etc.
I want to replace the comma with full stop only in 8th coloumn.
the output... (8 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Hi Guys,
Req your help in searching and replacing the word that comes after equals(=) symbol
I would like to replace the sting in bold with a string in variable.
d=ABCDF8C44C22
# grep -i NIM_MASTERID ${_NIMINFO}
export NIM_MASTERID=00CDF8C44C00
I'm looking to replace any word that... (4 Replies)
Dear friends,
please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories..
it is like this,
current directory contains
file1, file2, file3, dir1, dir2
and dir1 conatins
file4, file5
and dir2 contains
file6,... (9 Replies)