Swap two rows in a space delimited text file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Swap two rows in a space delimited text file?
# 1  
Old 11-04-2012
Swap two rows in a space delimited text file?

Hi,

How do you swap two rows in a space delimited text file? Thanks!
# 2  
Old 11-04-2012
Hi

Please post your sample input file and expected output file to give us some clarity.

Guru.
# 3  
Old 11-04-2012
Input:
Code:
1334 NA12146 0 0 1 -9 G A A G C A G G 
1347 NA11882 0 0 2 -9 G A A G C A G G A
1340 NA07056 0 0 2 -9 G A A G A A G G 
1408 NA12154 0 0 1 -9 A A G G A A G G

Swap lines 2 and 3

Output:
Code:
1334 NA12146 0 0 1 -9 G A A G C A G G 
1340 NA07056 0 0 2 -9 G A A G A A G G 
1347 NA11882 0 0 2 -9 G A A G C A G G A
1408 NA12154 0 0 1 -9 A A G G A A G G

# 4  
Old 11-04-2012
Hi

Code:
$ awk  'NR==2{x=$0;getline;print;$0=x;}1' file
1334 NA12146 0 0 1 -9 G A A G C A G G
1340 NA07056 0 0 2 -9 G A A G A A G G
1347 NA11882 0 0 2 -9 G A A G C A G G A
1408 NA12154 0 0 1 -9 A A G G A A G G

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 5  
Old 11-05-2012
@Guru, Can you explain above command
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

2. UNIX for Dummies Questions & Answers

Extracting rows from a space delimited text file based on the values of a column

I have a space delimited text file. I want to extract rows where the third column has 0 as a value and write those rows into a new space delimited text file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

3. UNIX for Dummies Questions & Answers

Adding tags to a specific column of a space delimited text file

I have a space delimited text file with two columns. I would like to add NA to the first column of the text file. Input: 19625 10.4791768259 19700 10.8146489183 19701 10.9084026759 19702 10.9861346978 19703 10.9304364984 Output: NA19625 10.4791768259 NA19700 10.8146489183... (1 Reply)
Discussion started by: evelibertine
1 Replies

4. UNIX for Dummies Questions & Answers

Converting a text file with irregular spacing into a space delimited text file?

I have a text file with irregular spacing between values which makes it really difficult to manipulate. Is there an easy way to convert it into a space delimited text file so that all the spaces, double spaces, triple spaces, tabs between numbers are converted into spaces. The file looks like this:... (5 Replies)
Discussion started by: evelibertine
5 Replies

5. Shell Programming and Scripting

Convert Rows to Space Delimited Line

Hello, I would like to convert a list of rows to a space separated line. Any ideas? Input file: "Administration Tools" "Design Suite" "Dial-up Networking Support" "Editors" desired output "Administration Tools" "Design Suite" "Dial-up Networking Support" "Editors" Thanks,... (4 Replies)
Discussion started by: jaysunn
4 Replies

6. UNIX for Dummies Questions & Answers

How do you view specific columns from a space delimited text file?

I have a space delimited text file with 1,000,000+ columns? I would only like to view specific ones (let's say through 1:10), how can I do that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

7. UNIX for Dummies Questions & Answers

Deleting cells that contain a specific number only from a space delimited text file

I have this space delimited large text file with more than 1,000,000+ columns and about 100 rows. I want to delete all the cells that consist of just 2 (leave 2's that are not by themselves intact): File before modification aa bb cc 2 NA100 dd aa b1 c2 2 NA102 de File after modification... (1 Reply)
Discussion started by: evelibertine
1 Replies

8. UNIX for Dummies Questions & Answers

Deleting columns from a space delimited text file

I have a space delimited text file with 1,000,000+ columns and 100 rows. I want to delete columns 2 through 5 (2 and 5) included from the text file. How do I do that? Thanks. (3 Replies)
Discussion started by: evelibertine
3 Replies

9. Shell Programming and Scripting

replace 3rd field of space delimited text file

how to replace the 3rd colum? Each line begins similarly, but they all ends variously. XX YY 03 variable text here XX YY 03 more variable text here XX YY 03 even more variable text here really long setence XX YY 03 variable numbers also appear 03 11. 123 456 XX YY 03 the occasional comma,... (4 Replies)
Discussion started by: ajp7701
4 Replies

10. UNIX for Dummies Questions & Answers

Searching for text in a Space delimited File

Hi I am trying to search a firewall syslog space delimeted file for all of the different tcp and udp destination ports. I know that grep will find lines that contain specific text. And I have tried using the the the cut command to cut out of the file certain colums. However the test I am... (6 Replies)
Discussion started by: andyblaylock
6 Replies
Login or Register to Ask a Question