Appending line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending line
# 1  
Old 06-16-2014
Appending line

Hi,

I have a file with below contents:
Code:
vi testcode.txt
123,
2,
3,
4,
5,
6,
7,
8


The above is an example, but in real I have hundreds of lines in the file, and I would like to append all the remaining lines to first line, and it should be looks below:

Code:
123,2,3,4,5,6,7,8

Anyway to do it with sed, awk or anything? Appreciate of any helps given.

Thanks
# 2  
Old 06-16-2014
Try:
Code:
tr -d '\n' < testcode.txt;echo

This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 06-16-2014
Or try:
Code:
 awk '{ORS=""}1' testcode.txt

This User Gave Thanks to chacko193 For This Post:
# 4  
Old 06-16-2014
This will leave the newline in place after the last line
Code:
paste -sd '\0' testcode.txt

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 06-16-2014
Try also

Code:
$ sed ':a;N;$!ba;s/\n//g' file

---------- Post updated at 02:07 PM ---------- Previous update was at 02:04 PM ----------

Code:
paste -sd '' file

---------- Post updated at 02:08 PM ---------- Previous update was at 02:07 PM ----------

Tested with Gnu Sed
Code:
$ sed --version
GNU sed version 4.2.1

This User Gave Thanks to Akshay Hegde For This Post:
# 6  
Old 06-16-2014
Note: -d '' will only work with GNU paste
These 2 Users Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Appending | (pipe) to end of each line which does not have it

I have a text file in which all records end with pipe character and newline, but a few do not have a pipe at the end. Something like this 1|John|32|US| 2|Matt|35|UK 3|Rex|36|EU| So in the above example the second line does not have a pipe at the end My requirement is to append a... (5 Replies)
Discussion started by: abhilashnair
5 Replies

2. Shell Programming and Scripting

Need help on appending line..

Hi Friends , I got struck in below scenario. Require help to get the desired output. I was going to other blog "Need help on appending all the lines in a file after a pattern is found." but was not able to make with respect to my requirement. Output Getting : -- Storage Group Name: ... (5 Replies)
Discussion started by: Vivek Iyer
5 Replies

3. Shell Programming and Scripting

Appending a word to the last line

Hi, I would like to append input given id at last line of file. For ex: In the following sample.txt file i would like to append the input given user id (after id6,id7) but it is adding on the next line instead same line. Sample.txt read=id1,id2,id3 write=id4,id5,id6 Thanks Raveendran (8 Replies)
Discussion started by: raveendran.l
8 Replies

4. Shell Programming and Scripting

Appending the first word of each line to the end of each line

Hi Experts, Am relatively new to shell programming so would appreciate some help in this regard. I am looking at reading from a file, line by line, picking the first word of each line and appending it to the end of the line. Any suggestions? INPUT FILE - 3735051 :... (7 Replies)
Discussion started by: hj007
7 Replies

5. Shell Programming and Scripting

awk;sed appending line to previous line....

I know this has been asked before but I just can't parse the syntax as explained. I have a set of files that has user information spread out over two lines that I wish to merge into one: User1NameLast User1NameFirst User1Address E-Mail:User1email User2NameLast User2NameFirst User2Address... (11 Replies)
Discussion started by: walkerwheeler
11 Replies

6. Shell Programming and Scripting

sed: appending alternate line after previous line

Hi all, I have to append every alternate line after its previous line. For example if my file has following contents line 1: unix is an OS line 2: it is open source line 3: it supports shell programming line 4: we can write shell scripts Required output should be line1: unix is an OS it is... (4 Replies)
Discussion started by: rish_max
4 Replies

7. Shell Programming and Scripting

Appending to the first line of a document

Hi all, I'm new to the forums and a total beginner with Unix. I've been given the seemingly simple task of writing a script that asks for two arguments: the first argument being a line of text, the second argument being a document. The script has to take the first argument of text and append it to... (5 Replies)
Discussion started by: oldhoi
5 Replies

8. Shell Programming and Scripting

Appending a line in a file after a particular line

Hello, I have got a C file in which I would like to add an include statement of my own. There are already a few include statements and mine should come right after the last existing one (to be neat). With grep I can get the lines containing the word 'include' and I guess I should feed the... (7 Replies)
Discussion started by: maxvirrozeito
7 Replies

9. Shell Programming and Scripting

Appending line ending with '}" to new line

Hello masters. I have a rather simple problem but its been killing me. I have a file "x" with only 1 line inside it. The line looks something like Now this is only part of the line. Its actually about 4000 characters. What i need to do is whenever there is a "}", i need to append the next... (4 Replies)
Discussion started by: aismann
4 Replies

10. Shell Programming and Scripting

Appending the line number and a seperator to each line of a file ?

Hi, I am a newb as far as shell scripting and SED goes so bear with me on this one. I want to basically append to each line in a file a delimiter character and the line's line number e.g Change the file from :- aaaaaa bbbbbb cccccc to:- aaaaaa;1 bbbbbb;2 cccccc;3 I have worked... (4 Replies)
Discussion started by: pjcwhite
4 Replies
Login or Register to Ask a Question