If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Text formating

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-23-04, 05:59
oluoch oluoch is offline
Registered User
 
Join Date: Jan 2004
Posts: 15
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
Reply With Quote
  #2 (permalink)  
Old 03-23-04, 07:33
gurey gurey is offline
Registered User
 
Join Date: Aug 2003
Location: Argentina
Posts: 780
Re: Text formating

Quote:
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
Reply With Quote
  #3 (permalink)  
Old 03-23-04, 07:45
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Try this :

Code:
awk -F'/' '{print $1}' input_file > output_file

sed 's!/.*!!' input_file > output_file
__________________
Jean-Pierre.
Reply With Quote
  #4 (permalink)  
Old 03-23-04, 07:59
oluoch oluoch is offline
Registered User
 
Join Date: Jan 2004
Posts: 15
Re: Text formating

Quote:
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?
Reply With Quote
  #5 (permalink)  
Old 03-23-04, 08:15
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
You can also try to use the cut command :
Code:
cut -d'/' -f1 input_file > output_file
__________________
Jean-Pierre.
Reply With Quote
  #6 (permalink)  
Old 03-23-04, 08:39
oluoch oluoch is offline
Registered User
 
Join Date: Jan 2004
Posts: 15
Quote:
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On