#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    3
    Rep Power
    0

    removing specific characters on the file


    hi. im new with shell scripting, please help me out.

    i need to make a script that will scan/parse one file and remove characters/word within that file.

    for example, file "abcd" contains this text:

    "abcdefghijklmnopqrs lmnopqrsabcdfghijk poiuytrewqabcdmnbvcxz"

    i need to delete the string "abcd"and replace it with space , so that the output file looks like this:

    " efghijklmnopqrs lmnopqrs fghijk poiuytrewq mnbvcxz"

    im using HP-UX. thanks!
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    4
    Rep Power
    0
    you could try this perl statement. It works on Solaris. No promises for HP-UX though:

    perl -i -pe "s/abcd/ /g" filename
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    India
    Posts
    61
    Rep Power
    12
    cat abcd.txt | sed "s/abcd/ /g" >>junk.txt; mv junk.txt abcd.txt;

    if you donot want the file to be changed then you can simply use

    cat abcd.txt| sed "s/abcd/ /g" to get the output

    Regards
    Regards
    JK
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    Originally posted by jayakhanna
    cat abcd.txt | sed "s/abcd/ /g" >>junk.txt; mv junk.txt abcd.txt;
    Use "cat junk.txt > abcd.txt" instead of the "mv" command. This way will not change the file's permissions.

    hth,
    M.

IMN logo majestic logo threadwatch logo seochat tools logo