Question in awk

Dear All,

How can we sort using awk?Is there anything by default

Please help me.

Regards,
Sukumar

Not sure about any function for sort in awk, but you can use the sort command within awk.

e.g.

head /etc/passwd | awk -F":" '{ print | "sort"}'

You don't need awk for this

head /etc/passwd | sort -t ":" -k1

would do

Hi vish_indian,

Thanks.But can we specify the field numbers to sort inside the awk like what we have specified in basic sort command.

Regards,
Sukumar.

You mean something like this:

awk 'NR<10{ print | "sort -t: -k3"}' /etc/passwd

or

awk 'NR<10{ print | "sort -t: -k3 -r"}' /etc/passwd

Its just calling the sort command inside awk, so all the options of sort should work

Hi vish_indian,

Many Thanks,for clearing my doubt.

Regards,
Sukumar.