How to append words at the end of first line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to append words at the end of first line
# 1  
Old 02-27-2008
How to append words at the end of first line

Hi Unix gurus

This is my first post here. I have a file which looks like this:

string1,string2
,string3
,string4
...
...

I need to append all words below first line to the first line, ie

string1,string2,string3,string4,...
Bear in mind that it is not known how many lines follow the first line.

Thanks
Lucas
# 2  
Old 02-27-2008
Quote:
Originally Posted by lmatlebyane
Hi Unix gurus

This is my first post here. I have a file which looks like this:

string1,string2
,string3
,string4
...
...

I need to append all words below first line to the first line, ie

string1,string2,string3,string4,...
Bear in mind that it is not known how many lines follow the first line.

Thanks
Lucas
Something like
Code:
tr -s '\n' ',' < t | sed -e "s/,$//g"


Last edited by vino; 02-27-2008 at 09:00 AM..
# 3  
Old 02-27-2008
Try this

Code:
xargs echo<filename

To store the output in new file

Code:
xargs echo<input_filename>output_filename

# 4  
Old 02-28-2008
Quote:
Originally Posted by Dhruva
Try this

Code:
xargs echo<filename

To store the output in new file

Code:
xargs echo<input_filename>output_filename

Hi Dhruva

Thanks for the solution, it works! I have one concern though, your code yields the following result:

string1,string2 ,string3 ,string4

How can I remove the spaces?

Thanks

Lucas
# 5  
Old 02-28-2008
Quote:
Originally Posted by vino
Something like
Code:
tr -s '\n' ',' < t | sed -e "s/,$//g"

Hi Vino, thanks for the reply.

Can you please explain how to use this command? When I try it it returns nothing.

Lucas
# 6  
Old 02-28-2008
In the code posted by #vino "t" is the input_file.

Did you try like that ?
# 7  
Old 02-28-2008
Yes I did, but there's no output:

root@sun6 # cat testfile
string1,string2
,string3
,string4

root@sun6 #tr -s '\n' ',' < testfile | sed -e "s/,$//g"
root@sun6 #


Thanks

Lucas
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append Pipes at the end of each line

Hi , I have pipe delimited file containing 12 columns having below data in AIX Input : A|B|C|D|E|F|G|H|I|J|K|L^M A1|B1|C1|D1|E1^M A2|B2|C2^M So in first row i have 11 pipes which is fine. In second row I have 4 pipes, so additional 7 pipes should get append In third row I have 2... (3 Replies)
Discussion started by: sonu_pal
3 Replies

2. Shell Programming and Scripting

Append this string to end of each line

Platform: Solaris 10 I have a file like below $ cat languages.txt Spanish Norwegian English Persian German Portugese Chinese Korean Hindi Malayalam Bengali Italian Greek Arabic I want to append the string " is a great language" at end of each line in this file. (3 Replies)
Discussion started by: omega3
3 Replies

3. Shell Programming and Scripting

find a certain line and append text to the end of the line

After I create printer queues in AIX, I have to append a filter file location within that printers custom file. within lets say test_queue.txt I need to find the row that starts with :699 and then I need to append on the end the string /usr/local/bin/k_portrait.sh. Now I've gotten the sed... (2 Replies)
Discussion started by: peachclift
2 Replies

4. 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

5. UNIX for Dummies Questions & Answers

Append characters to end of line

Coding in unix shell script. Hi All, Please help Thanks (6 Replies)
Discussion started by: sam12345
6 Replies

6. Shell Programming and Scripting

Append a string at the end of every line in a file

Hi Friends, I have a file with many lines as shown below. /START SAMPLE LINE/ M:\mmarimut_v6.4.0_pit_01\java\build.xml@@\main\v6.4.0_pit_a M:\mmarimut_v6.4.0_pit_01\port\Post.java@@\main\v6.4.0_pit_a M:\mmarimut_v6.4.0_pit_01\switchview\View.java@@\main\v6.4.0_pit_a /END SAMPLE LINE/ I... (1 Reply)
Discussion started by: nmattam
1 Replies

7. Shell Programming and Scripting

Copying x words from end of line to specific location in same line

Hello all i know it is pretty hard one but you will manage it all after noticing and calculating i find a rhythm for the file i want to edit to copy the last 12 characters in line but the problem is to add after first 25 characters in same line in other way too copy the last 12 characters... (10 Replies)
Discussion started by: princesasa
10 Replies

8. Shell Programming and Scripting

append end of line with 8 spaces

child_amt=$amount prev_line="$prev_line $child_amt" i am getting the result like this 21234567890001343 000001004OLFXXX029100020091112 0000060 but i want 8 spaces between the eg: 21234567890001343 000001004OLFXXX029100020091112 0000060 how can i do this in .ksh (1 Reply)
Discussion started by: kshuser
1 Replies

9. Shell Programming and Scripting

how to append the pattern at the end of the line

-Hi I have multiple files which contain a line with the word "exec". I need to add the following pattern " -cmode -ccheap" on the same line where "exec" is at the end. Any idea? Thanks a lot in advance to everybody... -A (2 Replies)
Discussion started by: aoussenko
2 Replies

10. 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
Login or Register to Ask a Question