1

How to swap 2 columns in file content

view story
linux-howto

http://www.linuxandlife.com – In this article, we will see several command methods about how to swap two columns or fields in a text file. Lets take the following file as example, the task is to swap the first 2 items of each line: Linux, and, Life Ubuntu, Kubuntu, Lubuntu Arch, Debian, Fedora Asus, Dell, Sony 1. Use awk A simple command with awk to do the task is: awk -F, '{print $2,$1,$3}' OFS=, file This command uses the print statement to print the fields in the desired order. The -F is to specify the input field separator and OFS for the output field separator. While this command is quite simpl (Distributions)