The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 03-02-2006
Registered User
 

Join Date: Feb 2006
Posts: 66
Subsrt ?

I have 7 fields, the last field is $7 and how do I write subsrt to get only
FieldActivity or FieldOrder or Case
ex: type = FieldActivity ;
it start at $7 and end at Modify ??

Thanks,


LMWC|02/28/2006 00:19:42|||||FieldActivity Modify 10071 20072 30073
CXT9|02/28/2006 02:36:31|||||FieldActivity Modify 10171 20172 30173
CXT9|02/28/2006 02:21:31|||||FieldOrder Modify 10141 20142
JAKN|02/28/2006 00:40:08|||||Case Modify 10101 20102 30103 40104
Reply With Quote
Forum Sponsor
  #2  
Old 03-02-2006
Registered User
 

Join Date: Jan 2006
Posts: 125
Hi, i am not sure how substr does it, i have an awk version if that will help you.

Code:
#!/bin/bash

awk -F"[ |]" '{print "Type is:" $8}' $filename  
#-F option sets <space> and <|> are separators. The 8th field is what you need.
Reply With Quote
  #3  
Old 03-03-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,003
Code:
echo 'LMWC|02/28/2006 00:19:42|||||FieldActivity Modify 10071 20072 30073' | nawk -F'|' '{print substr($NF, 1, index($NF, " "))}'
Code:
echo 'LMWC|02/28/2006 00:19:42|||||FieldActivity Modify 10071 20072 30073'  | sed 's#.*|\([^ ][^ ]*\).*#\1#'

Last edited by vgersh99; 03-03-2006 at 09:10 AM.
Reply With Quote
  #4  
Old 03-03-2006
Registered User
 

Join Date: Feb 2006
Posts: 66
Here is my code and it work

type = substr($7,1,index($7,"Modify")-2);

Hope that someone can learn it from this and thanks for your sharing
Cheers,
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0