Covert rows into one line data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Covert rows into one line data
# 1  
Old 06-09-2005
Covert rows into one line data

Hi ,

I have a file (a.txt ) with data :

17
18
19

I wants to make file which will have data as :

17,18,19

Can anyone please suggest me the way or any code snippet.

Thanks in advance.

Regards,
VJ
# 2  
Old 06-09-2005
Code:
tr '\n' ',' <a.txt

result:
Code:
17,18,19,

# 3  
Old 06-09-2005
rows in one line

temp=" " ;
while read line
do
temp=`echo "$temp";echo $line` ;
done < abc
echo $temp;
# 4  
Old 06-09-2005
You can do this,

awk '{ printf $0"," }END{print "\n"}' <filename>

hth.
# 5  
Old 06-09-2005
To remote last "," then,

awk '{ printf $0"," }END { printf "\n"}' a.txt | sed 's/,$//'

hth.
# 6  
Old 06-09-2005
Or....
Code:
awk -vORS="," -vTNR="`wc -l < a.txt`" '{if(TNR==NR){ORS="\n"}};1' a.txt

Cheers
ZB
# 7  
Old 06-09-2005
Or...
Code:
paste -sd, a.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove new line characters from data rows in a Pipe delimited file?

I have a file as below Emp1|FirstName|MiddleName|LastName|Address|Pincode|PhoneNumber 1234|FirstName1|MiddleName2|LastName3| Add1 || ADD2|123|000000000 2345|FirstName2|MiddleName3|LastName4| Add1 || ADD2| 234|000000000 OUTPUT : ... (1 Reply)
Discussion started by: styris
1 Replies

2. Shell Programming and Scripting

Data rearranging from rows to column

Hello Everyone, I have a input file looks like -0.005-0.004-0.003-0.002-0.00100.0010.0020.0030.0040.005My desired output should look like -0.005 -0.004 -0.003 -0.002 -0.001 0 0.001 0.002 0.003 0.004 0.005I had some success in getting the desired output. But i face a problem when i... (15 Replies)
Discussion started by: dinesh.n
15 Replies

3. Shell Programming and Scripting

Transpose data as rows using awk

Hi I have below requirement, need help One file contains the meta data information and other file would have the data, match the column from file1 and with file2 and extract corresponding column value and display in another file File1: CUSTTYPECD COSTCENTER FNAME LNAME SERVICELVL ... (1 Reply)
Discussion started by: ravlapo
1 Replies

4. Shell Programming and Scripting

Transpose Data from Columns to rows

Hello. very new to shell scripting and would like to know if anyone could help me. I have data thats being pulled into a txt file and currently have to manually transpose the data which is taking a long time to do. here is what the data looks like. Server1 -- Date -- Other -- value... (7 Replies)
Discussion started by: Mikes88
7 Replies

5. Shell Programming and Scripting

Counting rows line by line from a specific column using Awk

Dear UNIX community, I would like to to count characters from a specific row and have them displayed line-by-line. I have a file called testAwk2.csv which contain the following data: rabbit penguin goat giraffe emu ostrich I would like to count in the middle row individually... (4 Replies)
Discussion started by: vnayak
4 Replies

6. UNIX for Dummies Questions & Answers

Suggestion to convert data in rows to data in columns

Hello everyone! I have a huge dataset looking like this: nameX nameX 0 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 ............... nameY nameY 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 ..... nameB nameB 0 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 ..... (can be several thousands of codes) and I need... (8 Replies)
Discussion started by: kush
8 Replies

7. Shell Programming and Scripting

how to add if data in rows

Hi Friends, How to add if data is in different rows. Input: 1;20091102;20170930;-9.00;| 1;20091026;20170930;-2.00;| 1;20100720;20170930;-25.00;| 1;20090901;20211227;-10.00;| Output 9+2+25+10 = 46 Thx Suresh (4 Replies)
Discussion started by: suresh3566
4 Replies

8. Shell Programming and Scripting

Data in Rows to Columns

Hi, I am a beginner in bash&perl. I have data in form of:- A 1 B 2 C 3 D 4 E 5 I would like your help to find a simple way to change it to :- A B C D E 1 2 3 4 5 Any help would be highly appreciated. (8 Replies)
Discussion started by: umaars
8 Replies

9. Shell Programming and Scripting

column data to rows every n line

Hi every one, I am trying to organise an input text file like: input 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 into an output as following: output file 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 (5 Replies)
Discussion started by: nxp
5 Replies

10. Shell Programming and Scripting

chop a data file into rows

A very naive question... I have a file which has many rows and many columns and I would like to chop off the rows and create a new file per row named after the first column of every row + 1. The data files look like: # Donades de la trajectoria de la particula 60001 # 1:T 2:Massa 3:Rx 4:Ry 5:Rz... (7 Replies)
Discussion started by: pau
7 Replies
Login or Register to Ask a Question