Append the text file with comma at the end of every word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append the text file with comma at the end of every word
# 1  
Old 06-23-2011
Append the text file with comma at the end of every word

Hi folks,


Using shell, I am trying the append comma to every line of text.
the requirement is like, I have to open the txt file in unix and read line by line and should add comma at the end of every word to make it single line

txt file
-------
abc@gmail.com
bcd@gmail.com
efg@gmail.com
ghi@yahoo.com


Now the file should be seperated with comma as shown below
-----------------------------------------------------------

abc@gmail.com,bcd@gmail.com,efg@gmail.com,ghi@yahoo.com

Please help me.......
# 2  
Old 06-23-2011
You don't need to add new data, just change what's already there. Linefeeds can be changed into commas easily enough:
tr '\n' ',' < input > output

That might add a comma to the end, though. so tr '\n' ',' < input | sed 's/,$//' > output
# 3  
Old 06-23-2011
append the text file with comma at the end of every word

Thanks alot coronaa688 ..
But can you please eloborate it... What is input n output here ..

Thanks in advance ...
# 4  
Old 06-23-2011
input is the input file, output is the output file. They shouldn't be the same, since most UNIX utilities can't edit in-place.
# 5  
Old 06-23-2011
input and output are nothing but your "input" text file where the email id's exists and output is the file where you want to save the outcome.
# 6  
Old 06-23-2011
Quote:
Originally Posted by Corona688
tr '\n' ',' < input | sed 's/,$//' > output
Alternatively:
Code:
paste -sd, input > output

Regards,
Alister
# 7  
Old 06-24-2011
Awk solution..
Code:
awk '{NR==1?s=$0 : s=s","$0}END{print s}'  inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to append word at end of line

hello Team, I am looking for sed command or script which will append word at end of line. for example. I want to validate particular filesystem with mount |<filesystem name> command. if nodev parameter is not there then it should add in the fstab file with receptive to the filesystem. # mount... (8 Replies)
Discussion started by: ghpradeep
8 Replies

2. Shell Programming and Scripting

How to append word count at end of file?

Hi guys, I have to append the word count of a file at the end of the file name like this - > "filename_2345" where 2345 is the word count of "filename". How do i achieve this using one command ? I am not allowed to store the word count in a variable and then concatenate. Request your... (1 Reply)
Discussion started by: peter2312
1 Replies

3. Shell Programming and Scripting

Append text to end of every line

I've scoured the internet with mixed results. As an amateur I turn to the great minds here. I have a text file of 80 or so lines. I want to add ".pdf" to the end of each line. (For now that's it) Most of the internet points toward using "sed". I don't know coding but can figure things out... (4 Replies)
Discussion started by: spacebase
4 Replies

4. Shell Programming and Scripting

Append text to end of line on all lines

Hi, I've spent some time researching for this but can't seem to find a solution. I have a file like this 1234|Test|20101111|18:00|19:00There will be multiple lines in the file with the same kind of format. For every line I need to make it this 1234|Test|20101111|18:00|19:00||create... (5 Replies)
Discussion started by: giles.cardew
5 Replies

5. Shell Programming and Scripting

Append text from one file to another based on a search from the end of a document

Hi all, I have output files that are all text files with various different extensions. So, if I submit the input file "job_name.inp", when it finishes I get an output file "job_name.dat". A typical input file looks something like this: $CONTRL SCFTYP=RHF RUNTYP=ENERGY MAXIT=199 MULT=1... (4 Replies)
Discussion started by: marcozd
4 Replies

6. UNIX for Dummies Questions & Answers

How can I append a text at end of file after displaying the file

I have a file "sample.txt" with the content as below: Hi This is a Sample Text. I need a single command using cat which serve the following purpose. 1.display the contents of sample.txt 2.append some text to it 3. and then exit But, all should be served by a sinle command.:confused: (1 Reply)
Discussion started by: g.ashok
1 Replies

7. Shell Programming and Scripting

append some text message at the end of the file

Hi All, Please tell me how to append some text message at the end of the file. "File too large to view" example: xyz.log contains hhhhhhhhhhh hhhhhhjjjjjjjjj jjjjjjjjjjjjjjjjjjjjjj "File too large to view" Please advice (3 Replies)
Discussion started by: rajeshorpu
3 Replies

8. Shell Programming and Scripting

Sed : identify a pattern and append a word at the end of a line

Hello to all, On aix, I want to identify a term on a line in a file and then add a word at the end of the line identified. I do not want the word to be added when the line contains the symbol "#". I use the following command, but it deletes the term identified then adds the word. #sed... (4 Replies)
Discussion started by: dantares
4 Replies

9. Shell Programming and Scripting

Append text at end of the first line in a file

Hi I need to append some text @ end of the first line in a file. like myfile.txt list = a,b,c list.a=some.. I give the arg "d" . now it append at end of first line list=a,b,c,d list.a=some... Please help me out this (7 Replies)
Discussion started by: catgovind
7 Replies

10. UNIX for Dummies Questions & Answers

using sed to append text to the end of each line

Anyone know how to use SED to append a comma to the end of each line example: field1,field2,field3,field4 If i Cat /textfile ---- How can i append the end of /textfile with a comman? (8 Replies)
Discussion started by: Redg
8 Replies
Login or Register to Ask a Question