Results 1 to 2 of 2
I have a file that looks like this:
fv09 fv09-dev 5 y GRPLOAD V NONE 14 # fv09-Release
jul0809 jul0809-dev 5 y GRPLOAD V NONE 14 # jul0809-Release
jul2209 jul2209-dev ...
- 07-07-2009 #1
Perl substitute replace white space width maintain
I have a file that looks like this:
fv09 fv09-dev 5 y GRPLOAD V NONE 14 # fv09-Release
jul0809 jul0809-dev 5 y GRPLOAD V NONE 14 # jul0809-Release
jul2209 jul2209-dev 5 y GRPLOAD V NONE 14 # jul2209-Release
Now I need to replace string "NONE" with another string like "09/01/01:01:01". Now I can easily make this happened by doing :
$tmp = "09/01/01:01:01";
$str =~ s/NONE/$tmp/ ;
Now by doing this this will give me an output like :
fv09 fv09-dev 5 y GRPLOAD V NONE 14 # fv09-Release
jul0809 jul0809-dev 5 y GRPLOAD V 09/01/01:01:01 14 # jul0809-Release
jul2209 jul2209-dev 5 y GRPLOAD V NONE 14 # jul2209-Release
Which is more whie spaces after the value when I replace NONE (Assuming that I'm only changing the second line not all the lines)
But I want something like
fv09 fv09-dev 5 y GRPLOAD V NONE 14 # fv09-Release
jul0809 jul0809-dev 5 y GRPLOAD V 09/01/01:01:01 14 # jul0809-Release
jul2209 jul2209-dev 5 y GRPLOAD V NONE 14 # jul2209-Release
For doing this if I write command like :
$str =~ s/NONE /$tmp/ ;
THat didn't work because in my file I don't know whether I have tab/spaces etc after string "NONE"
- 07-07-2009 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
> tabs or spaces after NONE
well, how about changing such tabs as may be, to spaces?
If yr file is "f" then
sed 's/\t/ /g' <f
should replace each tab on a line, with a space. Then proceed
as before.the sun is new every day (heraclitus)


Reply With Quote