Re: Access 1st 12 charectors of a word.
Chris F.A. Johnson wrote:
> On 2006-08-22, Dave Kelly wrote:
>
>>I have a list that is 3 words to each line.
>>I know how to read the file.
>>I need only the first 12 character of the 3 word. This word is not
>>guaranteed to be 12 character long. This is where I'm stuck.
>>
>>Is there an equivalent to the old basic 'left$'? Where do I find it?
>
>
> To get the first 12 characters of the third word of every line:
>
> awk '{ printf "%s\n", substr($3,1,12) }'
>
Actually, that'll print the first 12 characters of the 3rd string of
non-blanks. For the OP - what's a "word"? For example, in this context:
Bob says "Hi!".
is <"Hi!".> a word, or <"Hi!">, or <Hi!> or <Hi> or something else?
Ed
|