Convert columns to single row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert columns to single row
# 1  
Old 06-02-2010
Convert columns to single row

Hello all

I have data like

Code:
1
2
3
4
5

I wish my output would be like

Code:
1,2,3,4,5

For this i have executed
Code:
'BEGIN {FS="\n"; ORS=","} {print $0}' test

and got the output as
Code:
1,2,3,4,5,

I do not want to have , at the end of 5. output should be like
Code:
1,2,3,4,5

If the input is
Code:
1
2
3

then output should be like 1,2,3

Please reply

Last edited by Scott; 06-02-2010 at 06:02 PM.. Reason: Please use code tags
# 2  
Old 06-02-2010
Code:
paste -sd, infile

# 3  
Old 06-02-2010
Code:
paste -s -d, inputfilename

# 4  
Old 06-02-2010
Quote:
Originally Posted by jim mcnamara
Code:
paste -s -d, inputfilename


Thankyou verymuch

Its working.
# 5  
Old 06-02-2010
Code:
awk '{printf ((NR-1&&NF)?",":x)$0}' file

# 6  
Old 06-03-2010
Try:

Code:
xargs < file | tr ' ' ','

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

2. Shell Programming and Scripting

Convert row to columns start from nth column

Dear All, We have input like this: 161 57 1378 176 1392 262 1444 441 1548 538 1611 670 1684 241 57 1378 208 1393 269 1447 444 1549 538 1610 677 1700 321 ... (4 Replies)
Discussion started by: attila
4 Replies

3. Shell Programming and Scripting

Convert columns to row using awk

Hi I need to convert some columns form a html file to rows. I do manage to make it works without help (some proud :) ) For some reason the offline status is not in bold, so I do need to remove the <b> tag from the other field to make this to work. All fields are not needed, so I test and... (5 Replies)
Discussion started by: Jotne
5 Replies

4. UNIX for Dummies Questions & Answers

Select 2 columns and transpose row by row

Hi, I have a tab-delimited file as follows: 1 1 2 2 3 3 4 4 a a b b c c d d 5 5 6 6 7 7 8 8 e e f f g g h h 9 9 10 10 11 11 12 12 i i j j k k l l 13 13 14 14 15 15 16 16 m m n n o o p p The output I need is: 1 1 a a 5 5 e e 9 9 i i 13... (5 Replies)
Discussion started by: mvaishnav
5 Replies

5. Shell Programming and Scripting

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

6. Shell Programming and Scripting

How to convert a single column into several columns?

Hi I have a ksh script which gives me the output as a single column with several rows like: AAA BBB CCC DDD EEE FFF GGG HHH III I want to be able to create a new file from this file which allows me to set the number of rows and columns in the new file, i.e. for this example, if I... (30 Replies)
Discussion started by: pinpe
30 Replies

7. Shell Programming and Scripting

How to convert 2 column data into multiple columns based on a keyword in a row??

Hi Friends I have the following input data in 2 columns. SNo 1 I1 Value I2 Value I3 Value SNo 2 I4 Value I5 Value I6 Value I7 Value SNo 3 I8 Value I9 Value ............... ................ SNo N (1 Reply)
Discussion started by: ks_reddy
1 Replies

8. UNIX for Advanced & Expert Users

convert rows to single row

Hi I want to convert multiple rows ro single row ,I have tried with below one but I am not getting what I am expecting.Please any idea a.txt conn1=stg conn2=dev path=\xxx\a1.txt fre=a conn1=stg conn2=dev path=\xxx\a2.txt freq=a awk '/a/{ORS=" "}{print}END{print "\n"}'... (5 Replies)
Discussion started by: akil
5 Replies

9. UNIX for Dummies Questions & Answers

convert matrix to row and columns

Dear Unix Gurus, I have a sample data set that looks like this y1 y2 y3 y4 y5 x1 0.3 0.5 2.3 3.1 5.1 x2 1.2 4.1 3.5 1.7 1.2 x3 3.1 2.1 1.0 4.1 2.1 x4 5.0 4.0 6.0 7.0 1.1 I want to open it up so that I get x1 y1 0.3 x2 y1 1.2 x3 y1 3.1 x4 y1 5.0 x1 y2 0.5 x2 y2... (3 Replies)
Discussion started by: tintin72
3 Replies

10. UNIX for Dummies Questions & Answers

How to convert a single column into several rows and columns?

I have a program which gives me the output as a single column with hundreds of rows like: 213 314 324 324 123 I want to be able to create a new file from this file which allows me to set the number of rows and columns in the new file, i.e. for this example, if I specify 3 rows and 2... (5 Replies)
Discussion started by: ashton_smith
5 Replies
Login or Register to Ask a Question