sed to copy 2nd line behind the 1st


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed to copy 2nd line behind the 1st
# 1  
Old 10-06-2009
sed to copy 2nd line behind the 1st

Hi all,

I need some help please. I got a file with two lines like this

111111111111111111
222222222222222222

and I want this

111111111111111111222222222222222

How can I do this with sed?
# 2  
Old 10-06-2009
Code:
sed 'N;s/\n//' infile

# 3  
Old 10-06-2009
Hi and thanks for the reply.
It kind of worked, now I get the following result.

11111111111111111^M22222222222222222^M

Any ideas how to remove the ^M

Cheers
# 4  
Old 10-06-2009
Quote:
Originally Posted by stinkefisch
Hi and thanks for the reply.
It kind of worked, now I get the following result.

11111111111111111^M22222222222222222^M

Any ideas how to remove the ^M

Cheers
^M is actually a Control-Key for Carriage Return. Your terminal type may strip this when viewing but they are there. I would recommend you clean up your original file OR try:
sed 'N;s/\n//' FILENAME | tr -d '\015'

Smilie
# 5  
Old 10-06-2009
Thanks mate
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies

3. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

4. UNIX for Dummies Questions & Answers

vim copy line and paste at the beginning, middle, and end of another line

How would you do vim copy line and paste at the beginning, middle, and end of another line. I know yy copies the whole line and p pastes the whole line, but on its own separate line. Sometimes I would like to copy a line to the beginning, middle, or end of another line. I would think this would be... (3 Replies)
Discussion started by: cokedude
3 Replies

5. Shell Programming and Scripting

1st column,2nd column on first line 3rd,4th on second line ect...

I need to take one column of data and put it into the following format: 1st line,2nd line 3rd line,4th line 5th line,6th line ... Thanks! (6 Replies)
Discussion started by: batcho
6 Replies

6. Shell Programming and Scripting

sed script - transform 1st matching line only

How do transform only the first line that matches my regex? I've tried q but it just quit my script in the middle. (9 Replies)
Discussion started by: yogert909
9 Replies

7. Filesystems, Disks and Memory

Tru64 Unix (HP) - copy file from 2nd HD to Boot HD

Hi, Here is some of the setup information on system: Tru64 UNIX OS and Two Hard Drives installed. One drive is boot drive and other is spare (Spare drive currently has some back up information on it). here is just a couple of the device/partition/mount points on boot drive. /dev/rz0a on... (4 Replies)
Discussion started by: willirb1
4 Replies

8. HP-UX

Copy file from 2nd HD to Boot HD

Hi, Here is some of the setup information on system: Tru64 UNIX OS and Two Hard Drives installed. One drive is boot drive and other is spare (Spare drive currently has some back up information on it). here is just a couple of the device/partition/mount points on boot drive. /dev/rz0a on... (4 Replies)
Discussion started by: willirb1
4 Replies

9. UNIX for Advanced & Expert Users

Sed - add text to start of line if 1st char anything but space

Problem: I have a lot of files, the files first line should always have 4 spaces before any text. Occasionally some of the files will miss the leading spaces and it's a problem. This is only in the first line. So if there are 4 spaces then text, do nothing. If there are not 4 spaces, add 4... (2 Replies)
Discussion started by: Vryali
2 Replies

10. Shell Programming and Scripting

sed to remove 1st two characters every line of text file

what is the sed command to remove the first two characters of every line of a text file? each line of the text file has the same amount of characters, and they are ALL NUMERIC. there are hundreds of lines though. for example, >cat file1.txt 10081551 10081599 10082234 10082259 20081134... (20 Replies)
Discussion started by: ajp7701
20 Replies
Login or Register to Ask a Question