cancel
Showing results for 
Search instead for 
Did you mean: 

awk - too many fields

SOLVED
Go to solution
Tony Walker
Frequent Advisor

awk - too many fields

Hi Guys,

I have a file with lines formated like so:

OPTION:uname1:uname2:uname3:etc........

What I want to do is add a new username to the end of a specific line within a script. My idea was something along the lines of (don't worry syntax isn't 100% as this is off the top of my head)

awk -F: '{if ( $1 == OPTION) { sub($0,$0:uname4) }; print $0 }'

In other words if the 1st field is the one I'm looking for add the username to the end of the line. The problem I have is I get the following error:

awk: Line uname1:uname2:uname3 cannot have more than 199 fields.

Is there a way round this??

Thanks,

Ton
5 REPLIES
H.Merijn Brand (procura
Honored Contributor
Solution

Re: awk - too many fields

# perl -aF: -pe '$F[0] eq "OPTION" and s/$/:uname4/'

or

# perl -pe '/^OPTION:/&&s/$/:uname4/'

or

# perl -pe 's/^(OPTION:.*)/$1:uname4/'

or

DMTOWTDI
Enjoy, Have FUN! H.Merijn
Armin Feller
Honored Contributor

Re: awk - too many fields

Hi,

awk can only support up to 199 fields.

Sorry, no other idear ;-(

Regards,
Armin
Tony Walker
Frequent Advisor

Re: awk - too many fields

Procura, thanks for that. I really need to start learning some Perl!!!!

Regards,

Tony
Christian Gebhardt
Honored Contributor

Re: awk - too many fields

Hi

you need perl (of course), but not for this task:

awk '/^OPTION/ {printf("%s:uname4\n",$0)}'

Chris
Tony Walker
Frequent Advisor

Re: awk - too many fields

Another good reply. I'm going to use this as I prefer to put commands in my script that I fully understand and my perl needs some work. Thanks again for everyones help.