0

Input file:

Ganesh
Gowri
Sam
Dave
Peter
Sheela

Output file:

Dave
Ganesh
Gowri
Peter
Sam
Sheela

Can someone please suggest the script for sorting the above file using arrays & awk...

2
  • Search man gawk | less +/^' *asort' & man gawk | less +/^' *asorti' Commented Feb 18, 2013 at 14:56
  • look at other questions here at stackoverflow - it is always better to write explicitly what kind of script you would like to deploy as well as describe by words what you'd like to achieve (alphabet sorting) Commented Feb 18, 2013 at 15:15

1 Answer 1

2

array & awk: asort()

kent$  echo "Ganesh
Gowri
Sam
Dave
Peter
Sheela"|awk '{a[NR]=$0}END{asort(a);for(i=1;i<=NR;i++)print a[i]}'
Dave
Ganesh
Gowri
Peter
Sam
Sheela

array & awk: asorti()

kent$  echo "Ganesh
Gowri
Sam
Dave
Peter
Sheela"|awk '{a[$0]}END{asorti(a);for(i=1;i<=NR;i++)print a[i]}' 
Dave
Ganesh
Gowri
Peter
Sam
Sheela
Sign up to request clarification or add additional context in comments.

1 Comment

How we can sort the lower and upper case alphabets using Awk command in Unix?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.