Subsrt ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Subsrt ?
# 1  
Old 03-02-2006
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
# 2  
Old 03-03-2006
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  
Old 03-03-2006
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 12:10 PM..
# 4  
Old 03-03-2006
Here is my code and it work

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

Hope that someone can learn it from this Smilie and thanks for your sharing
Cheers,
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Print line if subsrt matches array

Hi Folks! im printing all lines where the characters in position 270-271 match 33|H1|HA|KA|26 so i came up with this #!/bin/bash array=(33 H1 HA KA 26 ) for i in "${array}" do #echo $i awk '{ if (substr($0,270,2)~'/$i/') print; }' $1 >> $1.temp done It works fine . but... (2 Replies)
Discussion started by: phpsnook
2 Replies
Login or Register to Ask a Question