Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    15

    Unanswered: text formating with "/"

    Hello aigles

    I have a situation now where the data is in the fomat as below: i just need to remove all the text in one field that appears after the / but maintain all the other text in the row.

    2004032508 Rseln-NwMuthig/ain16x|8+2Mps/2b#1 communic. major
    2004032508 Milani-aka/Min8x2|8+2bps/Frae#1 equp std
    2004032508 Milmni-aka/Min8x2|8+2Mbps/2b#2 power. major
    2004032508 Milimni-aka/ain8x2|8+2bps/2b#1 communic. minor
    2004032508 Milini-Naa/ain8x2|8+2bps environm stable
    2004032508 KA-tirier/Mai16x2|8+2bps/2b#1 communic. major

    What i need to my output is:
    2004032508 Rseln-NwMuthig communic. major
    2004032508 Milani-aka equp std
    2004032508 Milmni-aka power. major
    2004032508 Milimni-aka communic. minor
    2004032508 Milini-Naa environm stable
    2004032508 KA-tirier communic. major

    Thank you for your help.

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    You can use awk to do that :
    Code:
    awk '{sub(/\/.*/,"",$2) ; print}' input_file
    { ... } : executed for each record
    sub(/\/.*/,"",$2) : substitute in field 2, '/' and all trailing characters by nothing.
    print : print the modified record
    Jean-Pierre.

  3. #3
    Join Date
    Jan 2004
    Posts
    15
    Originally posted by aigles
    You can use awk to do that :
    Code:
    awk '{sub(/\/.*/,"",$2) ; print}' input_file
    { ... } : executed for each record
    sub(/\/.*/,"",$2) : substitute in field 2, '/' and all trailing characters by nothing.
    print : print the modified record

    Hello Aigles,
    Thanks for the code but unfortunately am getting a syntax error on execution of the script as below:
    awk '{sub(/\/.*/,"",$2) ; print}' trans >trans.txt

    Could there be anything wrong?

    Thanks

  4. #4
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Try nawk instead of awk.
    If the problem persists, post the error messages.
    Jean-Pierre.

  5. #5
    Join Date
    Jan 2004
    Posts
    15
    Originally posted by aigles
    Try nawk instead of awk.
    If the problem persists, post the error messages.
    This is great. It works pretty well with nawk.

    Thanks alot

Posting Permissions

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