![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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.
|
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
Here is my code and it work
type = substr($7,1,index($7,"Modify")-2); Hope that someone can learn it from this Cheers, |
|||
| Google The UNIX and Linux Forums |