LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Swap column of text file (http://www.linuxquestions.org/questions/programming-9/swap-column-of-text-file-667620/)

kushalkoolwal 09-04-2008 04:10 PM

Swap column of text file
 
I have a file with following data (tab/space separated columns):
Code:

1 865249
2 134470
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 1
17 0
18 0
19 0
20 280

I would like to swap the two columns. I know it is got to be something very simple but can't seem to figure out.

Thanks

jcookeman 09-04-2008 04:43 PM

Code:

awk '{print$2, $1}' file

pixellany 09-04-2008 04:47 PM

awk -F" " '{print $2, $1}' filename > newfilename

(assumes that the column separator is a space)

Edit--beaten to the punch again....;)

ghostdog74 09-04-2008 08:38 PM

Code:

while read -r a b
do
 echo "$b $a"
done < file


kushalkoolwal 09-05-2008 11:30 AM

Solved
 
Thank you guys....Almost all the sample codes worked...


All times are GMT -5. The time now is 12:41 AM.