awk - Print variable number of colums from a starting column

Hi guys,

I usualy am able to google awk stuff but I can't find it so far and there are so many awking gurus here that I will give it a shot.

I want to print $1;$3;"$5 up to the $NF". In other words, I can have 1000 colums, but need to have $5 up to the end.

I started with the idea of "removing" the unwanted colums but the thing is that I need to have a field seperator (:wink: between $1 $3 and $5.

Original data looks like:

randomuser UID default_group GID Name of the user

And I would like it to look like:

randomuser;default_group;Name of the user

I still hate SOX audits ... I would do it manually, but we're talking about 50ish servers and 50ish groups ...

Any good ideas?

---------- Post updated at 11:03 AM ---------- Previous update was at 10:58 AM ----------

Nevermind ...

my_stupid_command | while read a b c d e; do echo $a";"$c";"$e;

It works just fine :slight_smile:

you can even save 2 variables

your_command | while read a b b c c; do echo $a";"$b";"$c; done

also :

your_command | sed 's/;[^;]*;/;/2;s/;[^;]*;/;/'

or

your_command | awk -F\; '{sub($2 FS $3 FS $4,$3)}1'
1 Like

see?

That's why I asked :slight_smile:

Too many ways to do the same thing