Find the answer to your Linux question:
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 ...
  1. #1
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Question 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"
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  2. #2
    tpl
    tpl is offline
    Linux 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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...