Huu Phan | Blog Linux operating system | Linux operating system -Blog Huu Phan | www.huuphan.com
huuphan.com. Powered by Blogger.

My blog about Open Source: Zimbra Mail Server,linux,bash script,centos,linux command...

How to change the order of columns in the output

In this tutorial, How to change the order of columns in the output of `uniq -c` command. I use read the file and show the unique Name from the file. How many time this name of the file?

The content of file as example below

[[email protected] ~]$ cat devopsroles.txt 

huu

huu

phan

van

dev

devopsroles

dev

huu

huu

I use awk, sort uniq command to read file and show the unique Name as example below

[[email protected] ~]$ cat devopsroles.txt | awk '{print $1}' | sort | uniq -c | sort -nr
      4 huu
      2 dev
      1 van
      1 phan
      1 devopsroles

Now, How to change the order of columns in the output of file

[[email protected] ~]$ cat devopsroles.txt | awk '{print $1}' | sort | uniq -c | sort -nr | awk '{ print $2,$1}'
huu 4
dev 2
van 1
phan 1
devopsroles 1
[[email protected] ~]$ cat devopsroles.txt | awk '{print $1}' | sort | uniq -c | sort -nr | awk '{ print $1,$2}'
4 huu
2 dev
1 van
1 phan
1 devopsroles

Conclusion

 How to change the order of columns in the output in file linux. I hope will this your helpful. Thank you for reading the Huuphan.com page!

post new :

Huu Phan | Blog Linux operating system | Huu Phan ~ Zimbra Mail Server,linux,bash script,centos,linux command | www.huuphan.com

This Blog is protected by DMCA.com