LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-03-2007, 11:16 PM   #1
ovince
Member
 
Registered: Mar 2007
Posts: 77

Rep: Reputation: 15
substitute 2 columns


Hi

Any idea how to substitute 2 columns in the datafile? For example how to substitute 4th and 5th columns in the datafile with 60 column. awk solution like

awk '{print $1,$2,$3,$5,$3,$6 ... $60}' fileName


works but writting all 60 columns in the command is painfull.

thanks
oliver
 
Old 05-04-2007, 12:17 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by ovince
Hi

Any idea how to substitute 2 columns in the datafile? For example how to substitute 4th and 5th columns in the datafile with 60 column. awk solution like

awk '{print $1,$2,$3,$5,$3,$6 ... $60}' fileName


works but writting all 60 columns in the command is painfull.

thanks
oliver
i suppose you want to substitute with another? not swap between $4 and $5 right?
Code:
awk '{$4 = "something"; $5 = "someother"; print $0}' file
if want to swap :
Code:
awk -F"." '{temp=$4;$4=$5;$5=temp;print $0}' file
 
Old 05-04-2007, 01:07 AM   #3
ovince
Member
 
Registered: Mar 2007
Posts: 77

Original Poster
Rep: Reputation: 15
I want swap (I could not recall the right word). The idea woth using temp is just fine. thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rearranging columns sureshbup Programming 3 11-01-2006 12:48 PM
Need Help With Columns Post Modern Programming 2 02-01-2006 11:18 AM
Vi Columns Chaitanyayardi Linux - Software 5 05-12-2005 07:27 AM
rows and columns digitalgravy Linux - General 2 03-16-2004 06:47 PM
How can I see the other 10 columns sakulagi Linux - Software 1 06-16-2003 09:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration