This will replace the original file. For just testing, remark the 2nd line.
This does indeed solve the problem but only for the example I gave, your solution would calculate and replace ALL the numbers into GB and that's fine if the user does specify the unit, however in another part of my script I choose the unit automatically (MB/GB/TB) therefor I need a solution to replace the numbers one by one (each different size unit) and not file wide!
Example:
Only the sed part that is actually suppose to replace the number doesn't work.
The more information you give, the more accurate the answer can hopefully be
Since awk works on every line of a file anyway (but the BEGIN and END part), there is no need to wrap it into a for-loop.
You can write all this in awk. Also you don't have to give the number via shell variable to awk. awk can just parse $0 (the whole line) or $1 (the 1st field).
For that sed line, which is not needed but as info: To let the shell explicit know where a variable starts and ends you should write them like this:
Also the output of awk will be the wanted output so you don't have to change it again with sed. This is redundant.
Stripping out redundancy etc, your script should maybe look more like:
The \n have been placed to the end of the lines since it looked somewhat strange.
Last edited by zaxxon; 03-17-2009 at 03:54 AM..
Reason: typos, i need coffee
I have a file lake this
cat ex1.txt
</DISCOUNTS>
<B2B_SPECIFICATION elem="0">
<B2B_SPECIFICATION elem="0">
<DESCR>Netti 2 </DESCR>
<NUMBER>D02021507505</NUMBER>
</B2B_SPECIFICATION>
<B2B_SPECIFICATION elem="1">
<DESCR>Puhepaketti</DESCR>... (2 Replies)
Replace first 3 characters in a unix file (say replace "A&B" with "C&D") in all lines of the file. Need a sed or awk script to do this. Kindly help!
-Kumar (4 Replies)
Hi everybody,
I am a newbie in shell scripting and I'm trying to write a script which reads lines from a file, searching some of this lines to change a specified number. I want to replace the line for another in the file.
I have to replace multiples lines, so I have a for. Now I am trying with... (1 Reply)
Hello,
I have 8 lines containing these unique words in both files
645147468537
673962863160
673962864957
691717701950
707917019907
790085591726
792975507744
852174812753
file.dat.orig (has 1000 lines) and file.dat(has only 8 lines)
I want to replace those lines in file.dat.orig by... (1 Reply)
Hi all,
I have two parameter blocks in a configuration file, file1.conf.
First parameter block starts with PWAT-PARM1 and
ends with END PWAT-PARM1.
Second parameter block starts with PWAT-PARM2 and
ends with END PWAT-PARM2 (please see below in file1.conf).
file1.conf is fixed width... (8 Replies)
Hello
I am a beginner in shell script.
I was trying to find a way to replace multiple lines of a file with different set of multiple line.
sed -n '/begin/,/end/p' < sample1.txt >test.txt
UNEDITED=`cat test.txt`
vi test.txt
EDITED=`cat test.txt`... (2 Replies)
Hi all,
I am new to UNIX, so sorry if my question seem stupid to u.
well i want to replace the first character of first 30 lines of a file, only if the first character is h.
and
in anothe script i want to replace a particular string/character say hello/h of a file.Condition: It should... (1 Reply)