Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I have a txt file which contai

Status
Not open for further replies.

nithink

Programmer
Nov 7, 2002
92
US
Hi,
I have a txt file which contains 25 lines of data like given below.

1,0.00
2,0.00
3,0.00
...
..
25,0.00

i need to replace those 0.00 with another value 0.25
Can you pls let me know how this can be done ?
Thanks
 
#!/bin/ksh

file='myFile.txt'

ex - &quot;${file}&quot; <<EOF
%s/,0.00/,0.25/g
wq!
EOF
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks olded, but when i give ur command &quot;sed&quot;
it just displays the changed values in the command prompt
but it doesn't get changed in the original data file. It still remains 0.00. I want to permanently replace 0.00 with 0.25. Can yu help me out please.

Thanks vgersh, but i need to do it in csh only. Any suggestions welcome.
 
#!/bin/csh
#
# not a really big fan of csh, but......
#
set file='myFile.txt'

ex - &quot;${file}&quot; <<EOF
%s/,0.00/,0.25/g
wq!
EOF vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
The sed command should be output to another file
and that file is then moved to the current file, like this:

sed &quot;s/0.00/0.25/g&quot; data.file > datafile.tmp
mv datafile.tmp data.file

Another way to do this with perl w/o creating the tmp file is:
perl -p -i -e &quot;s/.00$/.25/g;&quot; datafile

This edits the file in place like the csh 'ex' solution.

-jim
 
Thanks JIM. it worked fine.

Thanks to OLDED & VGERSH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top