Copy and Paste Columns in a Tab-Limited Text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy and Paste Columns in a Tab-Limited Text file
# 1  
Old 05-26-2011
Copy and Paste Columns in a Tab-Limited Text file

I have this text file with a very large number of columns (10,000+) and I want to move the first column to the position of the six column so that the text file looks like this:

Before cutting and pasting
ID Family Mother Father Trait Phenotype
aaa bbb ccc ddd eee ddd
fff ggg hhh iii jjj ggg


Family Mother Father Trait ID Phenotype
bbb ccc ddd eee aaa ddd
ggg hhh iii jjj fff ggg

It is a tab-limited text file. How do I achieve this? Thank you!
# 2  
Old 05-26-2011
In your example, ID gets to be the 5th column, in your description you say 6th.
Here is the version for 5th; adjust as needed:
Code:
awk '{tmp=$1; for(i=2;i<6;i++)$(i-1)=$i; $5=tmp}1' FS='\t' OFS='\t' data

# 3  
Old 05-26-2011
Disregard -- I misread the OP
This should be more efficient. All you need to do is exchange the two fields rather than looping.

Code:
awk ' BEGIN { OFS = "\t"; } {x=$1; $1=$6; $6=x; print; }'  <input-file


Last edited by agama; 05-26-2011 at 09:52 PM..
# 4  
Old 05-26-2011
I don't think so. OP needs the second column become first, etc. after the operation. OP does not want the sixth field to become first.
This User Gave Thanks to mirni For This Post:
# 5  
Old 05-26-2011
Quote:
Originally Posted by mirni
I don't think so. OP needs the second column become first, etc. after the operation. OP does not want the sixth field to become first.
Oh how embarrassing. I completely misread the OP. You are absolutely correct.
# 6  
Old 05-26-2011
Happened to me before Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash copy and paste text in file from one position to another

Hi I have a text file with lines beginning with 71303, 71403, 71602, I need to copy the 10 digit text at position 30 on lines beginning with 71303 (5500011446) to position 99 on every line beginning with 71602 (see example below), There may be many 71303 lines but I need the text copying to... (2 Replies)
Discussion started by: firefox2k2
2 Replies

2. Shell Programming and Scripting

Copy and paste text inside a xml file

I have a really big XML file. I need copy the value of one tag inside another one tag. I try to publish one example. <channel update="i" site="merge-xmltv" site_id="" xmltv_id="Rai 1">Rai 1</channel> <channel update="i" site="merge-xmltv" site_id="" xmltv_id="Rai 1 +2HD">Rai 1... (6 Replies)
Discussion started by: Tapiocapioca
6 Replies

3. Shell Programming and Scripting

Make copy of text file with columns removed (based on header)

Hello, I have some tab delimited text files with a three header rows. The headers look like, (sorry the tabs look so messy). index group Name input input input input input input input input input input input... (9 Replies)
Discussion started by: LMHmedchem
9 Replies

4. Shell Programming and Scripting

Remove blank columns from a tab delimited text file

Hello, I have some tab delimited files that may contain blank columns. I would like to delete the blank columns if they exist. There is no clear pattern for when a blank occurs. I was thinking of using sed to replace instances of double tab with blank, sed 's/\t\t//g' All of the examples... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

5. UNIX for Dummies Questions & Answers

Deleting columns from a tab delimited text file?

I have a tab limited text file with 10000+ columns. I want to delete columns 6 through 23, how do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

6. UNIX for Dummies Questions & Answers

How to convert text to columns in tab delimited text file

Hello Gurus, I have a text file containing nearly 12,000 tab delimited characters with 4000 rows. If the file size is small, excel can convert the text into coloumns. However, the file that I have is very big. Can some body help me in solving this problem? The input file example, ... (6 Replies)
Discussion started by: Unilearn
6 Replies

7. Shell Programming and Scripting

to parse (or grep) a number from a datafile and write it to tab limited file

Hi All, I have a folder that contain 100's of subfolders namely: Main folder -> GHFG - Subfoders ->10 100 234 102 345 .. .. ... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

8. Solaris

Copy and paste text from a word document into a txt file in vi

Hello, Can anybody please tell me how we can copy and paste text from a word document into a text file that we are editing in vi? Is it possible to do that while we are editing the text file in vi in insert mode? Thanks, (3 Replies)
Discussion started by: Pouchie1
3 Replies

9. Shell Programming and Scripting

Copy Limited rows from one file to another

Hi, The file contains 1000 of rows can you please let me know How to copy 1-10 and 30-40 rows from one file to another. thanks :) (3 Replies)
Discussion started by: ravi214u
3 Replies

10. UNIX for Dummies Questions & Answers

Copy/Paste text as commands in AIX

Hello, I'm absolutely new to this world... but I've a problem with a terminal connected via PuTTY (or Termlite) to an AIX 5.1 application. The problem: I need to paste from clipboard a text containing both input text strings and special keys as ESC, Arrows and so on, to execute in the AIX... (1 Reply)
Discussion started by: Daniele11
1 Replies
Login or Register to Ask a Question