On 1/28/2008 1:07 PM, Janis Papanagnou wrote:
> mooshak@[EMAIL PROTECTED]
wrote:
>
>>Hi All,
>>
>>My apologies if this has been covered in the past.
>>
>>I am trying to parse lines in a file. I would like to catpure
>>anything after $8 as one variable. For example, in the line below, I
>>would like "insert into schema.tab values" to be $8. By default, awk
>>parses the word 'insert' as $8.
>>
>>Is there an easy way to do it?
>>
>>
>>0x078000007E1B3840 14 41382 1 1 2
>>2 insert into schema.tab values
>
>
> What's in between the first 7 numbers; is that TAB, or a fixed number
> of white space characters, or an arbitrary sequence of white space
> characters?
>
> To start at fixed column number use substr($0,start_index), otherwise
> use match(); in the first (the TAB) case it might be
>
> awk 'sub(/.*\t/,"")||1'
I wouldn't bother with the "||" as I don't think it adds anything:
awk 'sub(/.*\t/,"")1'
but in reality I'd use:
awk -F'\t' '{print $NF}'
>
> otherwise the pattern is more lengthy, something like
>
> awk 'BEGIN{b="[[:blank:]]+";n="[^[:blank:]]+"}
> sub(n b n b n b n b n b n b n b,"")||1'
or it could be:
awk 'sub(/.*[[:blank:]][[:blank:]]/,"")1'
if there's always more than 1 space before "insert" and always less than 2
spaces after it.
Or, with a POSIX awk:
awk 'sub(/^[[:blank:]]*([^[:blank:]]*[[:blank:]]*){7}/,"")1'
(use "--re-interval" with GNU awk).
Ed.
> If you don't care about white space preservation in the remaining string
> you may also use the method to assign empty strings to the first fields
>
> {$1=$2=$3=$4=$5=$6=$7=""; print substr($0,8)}
>
>
> Janis
>
>
>>
>>Thanks
>>
>>Moosh
>


|