Line processing

Tags
shell scripts

 
Thread Tools Search this Thread
# 1  
Old 01-30-2012
Line processing

If I have a line say like this

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

I want column 16 to be moved into column 4 and the rest same, like this

1 2 3 16 5 6 7 8 9 10 11 12 13 14 15

Using awk, I know that replacing $4 with $16 and typing all the column numbers will help. But, I have more than 100 columns and I can't type all of them. Is there an easy way to specify what column to copy into what and print the rest?

Thanks in advance
# 2  
Old 01-30-2012
Why would you need to type all the column numbers?
Code:
awk '{$4=$16;$16=""}1' file

This User Gave Thanks to bartus11 For This Post:
jacobs.smith (01-30-2012)
# 3  
Old 01-30-2012
Try this:

Code:
awk '{temp = $4; $4 = $16; $16 = temp} {print $0}' file

This User Gave Thanks to pvamsikr For This Post:
jacobs.smith (01-30-2012)
# 4  
Old 01-30-2012
Quote:
Originally Posted by pvamsikr
Try this:

Code:
awk '{temp = $4; $4 = $16; $16 = temp} {print $0}' file


Thanks this works. But, it even prints the 16th column too, which I don't want. How do I do it?
# 5  
Old 01-30-2012
sorry, did not read your first thread clearly.. if you dont want to print 16th column, use this.. It same as the solution provided by "bartus11"

Code:
awk '{$4 = $16; $16 = ""} {print $0}' file

This User Gave Thanks to pvamsikr For This Post:
jacobs.smith (01-31-2012)

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
File Processing: Handling spaces in a line baanprog UNIX for Advanced & Expert Users 13 11-15-2013 01:49 PM
Processing Multiple Arguments in Command Line Options Jay Deshpande Shell Programming and Scripting 7 07-08-2013 03:18 AM
[awk] line by line processing the same file origamisven Shell Programming and Scripting 6 10-02-2012 09:03 AM
[string processing]Adding new line in file animesharma Shell Programming and Scripting 11 09-21-2011 08:32 AM
Individual Line processing in awk ddspark Shell Programming and Scripting 3 08-09-2011 05:28 PM
Text Processing with a line break patric2326 Shell Programming and Scripting 8 03-01-2011 10:06 AM
Add message in a command line processing k_manimuthu Shell Programming and Scripting 4 11-17-2010 09:35 AM
AWK: Remove spaces before processing each line? kevintse Shell Programming and Scripting 6 08-23-2010 10:23 PM
reading a file inside awk and processing line by line Anteus Shell Programming and Scripting 6 06-22-2009 12:05 PM
awk, perl Script for processing a single line text file hmsadiq Shell Programming and Scripting 1 04-12-2009 04:44 PM
Reading a file line by line and processing for each line sagarparadkar Shell Programming and Scripting 6 03-02-2009 11:59 AM
File processing line by line suma Shell Programming and Scripting 1 07-19-2008 07:01 PM
AWK Multi-Line Records Processing RacerX Shell Programming and Scripting 10 10-18-2007 09:46 PM
processing line in file fablef00 Shell Programming and Scripting 8 01-23-2006 11:41 AM