Line processing


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
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  
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:
# 4  
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  
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:
Login or Register to Reply

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

More UNIX and Linux Forum Topics You Might Find Helpful
[awk] line by line processing the same file
origamisven
Hey, not too good at this, so I only managed a clumsy and SLOW solution to my problem that needs a drastic speed up. Any ideas how I write the following in awk only? Code is supposed to do... For every line read column values $6, $7, $8 and do a calculation with the same column values of every...... Shell Programming and Scripting
6
Shell Programming and Scripting
reading a file inside awk and processing line by line
Anteus
Hi Sorry to multipost. I am opening the new thread because the earlier threads head was misleading to my current doubt. and i am stuck. list=`cat /u/Test/programs`; psg "ServTest" | awk -v listawk=$list '{ cmd_name=($5 ~ /^/)? $9:$8 for(pgmname in listawk) ...... Shell Programming and Scripting
6
Shell Programming and Scripting
Reading a file line by line and processing for each line
sagarparadkar
Hi, I am a beginner in shell scripting. I have written the following script, which is supposed to process the while loop for each line in the sid_home.txt file. But I'm getting the 'end of file' unexpected for the last line. The file sid_home.txt gets generated as expected, but the script...... Shell Programming and Scripting
6
Shell Programming and Scripting
File processing line by line
suma
Hi, I am doing file processing line by line. while reading each line at a specified location I am searching for a particular character and then write that line to another file. Problem is while writing to another file it was supressing the spaces, which I don't want to do. Any help is...... Shell Programming and Scripting
1
Shell Programming and Scripting
processing line in file
fablef00
Hi I amtrying to read the lines from a file, these lines are absolute paths in the system. I want to check if these paths exists, if they doesn't I want to create that path and put a file in that location/path. I had no trouble filtering these paths out using awk, grep, uniq etc but when it...... Shell Programming and Scripting
8
Shell Programming and Scripting