to append data in a single row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting to append data in a single row
# 1  
Old 04-27-2009
to append data in a single row

Hi all,

I need a logic in UNIX to append contents of a file in same row, where the original contents are found one below the other. For example.

My i/p file contains:
“user1”,”employee1”,”04/28/2009”
“5678”
“78”
“user2”,”employee2”,”04/30/2009”

I want my output as
“user1”,”employee1”,”04/28/2009”,”5678”,”78”,“user2”,”employee2”,”04/30/2009”

Please look at the comma between each entry. Each value should be delimited by comma.

Regards Meera
# 2  
Old 04-27-2009
Quote:
Originally Posted by Sgiri1
Hi all,

I need a logic in UNIX to append contents of a file in same row, where the original contents are found one below the other. For example.

My i/p file contains:
“user1”,”employee1”,”04/28/2009”
“5678”
“78”
“user2”,”employee2”,”04/30/2009”

I want my output as
“user1”,”employee1”,”04/28/2009”,”5678”,”78”,“user2”,”employee2”,”04/30/2009”

Please look at the comma between each entry. Each value should be delimited by comma.

Regards Meera
Code:
Code:
cat file | tr '\n' ',' >> file1

$ cat file
"user1","employee1","04/28/2009"
"5678"
"78"
"user2","employee2","04/30/2009"

$ cat file1
"user1","employee1","04/28/2009","5678","78","user2","employee2","04/30/2009"

Does this help?

Cheers,
Sai
# 3  
Old 04-28-2009
Code:
cat a.txt | tr "\n" ","

# 4  
Old 04-28-2009
/usr/xpg4/bin/awk '/04\/30\/2009/{print;next}NF{printf("%s ",$0)}' $file

here 04/30/2009 is the end of your file
# 5  
Old 04-30-2009
Quote:
Originally Posted by reddybs
Code:
Code:
cat file | tr '\n' ',' >> file1

$ cat file
"user1","employee1","04/28/2009"
"5678"
"78"
"user2","employee2","04/30/2009"

$ cat file1
"user1","employee1","04/28/2009","5678","78","user2","employee2","04/30/2009"

Does this help?

Cheers,
Sai

hi sai...im getting the o/p as follows..

“user1”,”employee1”,”04/28/2009”,“5678”,“78”,“user2”,”employee2”,”04/30/2009”,,

there are two commas at the end..i dont need comma after the last entry. can you please help me with this?
# 6  
Old 04-30-2009
I think that you have two empty lines at the end of your original file, get rid of them
# 7  
Old 04-30-2009
Quote:
Originally Posted by Sgiri1
hi sai...im getting the o/p as follows..

“user1”,”employee1”,”04/28/2009”,“5678”,“78”,“user2”,”employee2”,”04/30/2009”,,

there are two commas at the end..i dont need comma after the last entry. can you please help me with this?
Try this. This is probably because you have an empty line in the file.

sed '/^$/d file | tr '\n' ',' >> file1

cheers,
Devaraj Takhellambam
Login or Register to Ask a Question

Previous Thread | Next Thread

9 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

Read line from the file and append it to each row

Hi All, We have a file in the following format: 0.010000 $ ITI 11 LV2 $ 40456211 $ 0.135000 $ ITI 11 LV1 $ 40512211 $ 1.215600 $ ITI 11 ITI3 $ 41406211 $ 24/05/2014 14:05:02 0.030000 $ ITI 11 LV2 $ 40456211 $ ... (3 Replies)
Discussion started by: gauravsinghal79
3 Replies

3. Emergency UNIX and Linux Support

[Solved] Mysql - Take data from row and copy it to another row

Sorry if I repost my question in this section, but I'm really in a hurry since I have to finish my work... :( Dear community, I have a table with two rows like: Row1 Row2 ======= ======= 7,3 text 1 1,3 text 2 1,2,3 blabla What i need to do is add/copy... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

4. Shell Programming and Scripting

Append data to new row in CSV file every day

Hi All I will run the same script every day in corn and output should go to same CSV file but in different row with dates on it. Below is my example in attached format. Script i am using to collect switch port online DATE=`date '+%d-%m-%y'` for f in `cat... (1 Reply)
Discussion started by: ranjancom2000
1 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

Append test as a row

I searched the thread i couldn't able to find the solution that's y posted here.. help me i have a file as setting field value A 0 setting field value B 2 setting field value C 3 some text ------ --- some text setting field value A 0 setting field value B 2 setting field value... (9 Replies)
Discussion started by: greenworld123
9 Replies

7. Shell Programming and Scripting

Append Second Row to First Row @ end in a file

Hi I want to append line 2n to 2n-1 line where n=1...LastLine in my file. eg: Actual File: Hello Everyone Welcome TO Unix I need Your help Required File: HelloEveryone WelcomeTO Unix I needYour help (5 Replies)
Discussion started by: dashing201
5 Replies

8. Shell Programming and Scripting

Add value of each row when each row has different data ype

Guys -- I am noob and I am really strugging on this one. I cant even write the pseudo code for it. I have a file that spits values in individual rows as such: file: user date type size joe 2005-25-09 log 1 joe 2005-25-09 snd 10 joe 2005-25-09 rcd 12 joe 2005-24-09 log 2 joe... (1 Reply)
Discussion started by: made2last
1 Replies

9. Shell Programming and Scripting

How to insert data befor some field in a row of data depending up on values in row

Hi I need to do some thing like "find and insert before that " in a file which contains many records. This will be clear with the following example. The original data record should be some thing like this 60119827 RTMS_LOCATION_CDR INSTANT_POSITION_QUERY 1236574686123083rtmssrv7 ... (8 Replies)
Discussion started by: aemunathan
8 Replies
Login or Register to Ask a Question