Results 1 to 6 of 6

Thread: Text formating

  1. #1
    Join Date
    Jan 2004
    Posts
    15

    Unanswered: Text formating

    Could anyone help me with this using sed or Awk.
    I have got a text file with so many lines and i need to strip off unwanted xtars as below.
    Input file contains:
    Upperlands-Roadside/Main16x2|8+2Mbps/2Mb#1
    Telsat-vineland/Main16x2|8+2Mbps/2Mb#1
    market-university/Main8x2|8+2Mbps/2Mb#2
    Runway-hall/Frame16x2|8+2Mbps/2Mb#1
    Telsat-vineland/Main16x2|8+2Mbps/2Mb#1
    market-university/Main8x2|8+2Mbps/2Mb#2
    Runway-hall/Frame16x2|8+2Mbps/2Mb#1

    All i need in Output file is:

    Upperlands-Roadside
    Telsat-vineland
    market-university
    Runway-hall
    Telsat-vineland
    market-university
    Runway-hall

    I have tried using this sed command to find the unwanted xters starting from the / and replacing it with no space but it does not work.
    NB: Remember there are so many other columns in the input file

    sed 's/[/][a-zA-Z0-9].[/]//'g inputfile > outputfile

  2. #2
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    780

    Re: Text formating

    Originally posted by oluoch
    Could anyone help me with this using sed or Awk.
    I have got a text file with so many lines and i need to strip off unwanted xtars as below.
    Input file contains:
    Upperlands-Roadside/Main16x2|8+2Mbps/2Mb#1
    Telsat-vineland/Main16x2|8+2Mbps/2Mb#1
    market-university/Main8x2|8+2Mbps/2Mb#2
    Runway-hall/Frame16x2|8+2Mbps/2Mb#1
    Telsat-vineland/Main16x2|8+2Mbps/2Mb#1
    market-university/Main8x2|8+2Mbps/2Mb#2
    Runway-hall/Frame16x2|8+2Mbps/2Mb#1

    All i need in Output file is:

    Upperlands-Roadside
    Telsat-vineland
    market-university
    Runway-hall
    Telsat-vineland
    market-university
    Runway-hall

    I have tried using this sed command to find the unwanted xters starting from the / and replacing it with no space but it does not work.
    NB: Remember there are so many other columns in the input file

    sed 's/[/][a-zA-Z0-9].[/]//'g inputfile > outputfile
    HI,
    Please test follow

    cat file |awk -F"\/" '{print $1}'
    or
    sed 's/[\/][a-zA-Z0-9].[\/]//'g inputfile > outputfile

  3. #3
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Try this :

    Code:
    awk -F'/' '{print $1}' input_file > output_file
    
    sed 's!/.*!!' input_file > output_file
    Jean-Pierre.

  4. #4
    Join Date
    Jan 2004
    Posts
    15

    Re: Text formating

    Originally posted by gurey
    HI,
    Please test follow

    cat file |awk -F"\/" '{print $1}'
    or
    sed 's/[\/][a-zA-Z0-9].[\/]//'g inputfile > outputfile

    I have tried both the sed and awk options but still do not work. Anymore ideas please to try?

  5. #5
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    You can also try to use the cut command :
    Code:
    cut -d'/' -f1 input_file > output_file
    Jean-Pierre.

  6. #6
    Join Date
    Jan 2004
    Posts
    15
    Originally posted by aigles
    Try this :

    Code:
    awk -F'/' '{print $1}' input_file > output_file
    
    sed 's!/.*!!' input_file > output_file

    Thanks alot they all worked very well

Posting Permissions

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