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 with "/"

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-29-04, 09:23
oluoch oluoch is offline
Registered User
 
Join Date: Jan 2004
Posts: 15
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.
Reply With Quote
  #2 (permalink)  
Old 03-29-04, 09:54
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
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.
Reply With Quote
  #3 (permalink)  
Old 03-30-04, 00:40
oluoch oluoch is offline
Registered User
 
Join Date: Jan 2004
Posts: 15
Quote:
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
Reply With Quote
  #4 (permalink)  
Old 03-30-04, 00:44
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Try nawk instead of awk.
If the problem persists, post the error messages.
__________________
Jean-Pierre.
Reply With Quote
  #5 (permalink)  
Old 03-30-04, 01:15
oluoch oluoch is offline
Registered User
 
Join Date: Jan 2004
Posts: 15
Quote:
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
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