Sed line concatenation problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed line concatenation problem
# 1  
Old 11-11-2009
Sed line concatenation problem

I have a somewhat bizarre problem when trying to concatenate lines in a file.
Using
Code:
cat file.txt | sed -e :a -e '/$/N;s/\n/ /;ta'

the output in file.txt should go from
Code:
1
2
3

to
Code:
1 2 3

instead I only get the last line or
Code:
3

.
I find that if I open the file in gedit and hit delete in front of every line the code works. I don't believe there are any spaces in front of the lines and the code should still work even if there were. What is going wrong? How do I go about fixing this?
# 2  
Old 11-11-2009
Code:
tr "\n" " "  < file

# 3  
Old 11-11-2009
Quote:
Originally Posted by ghostdog74
Code:
tr "\n" " "  < file

Unfortunately this does not work with the file in question. Is there some way to mimic delete at the beginning of every line?
# 4  
Old 11-11-2009
does not work isn't very good response. Show all you have got. error messages etc... if your actual file is not the same as what you posted, then how do you expect to get correct results when people actually work on your sample file?
# 5  
Old 11-11-2009
Quote:
Originally Posted by ghostdog74
does not work isn't very good response. Show all you have got. error messages etc... if your actual file is not the same as what you posted, then how do you expect to get correct results when people actually work on your sample file?
There were no error messages. It simply doesn't output properly. Here is the actual file
h t t p ://rapidshare.com/files/305361050/lsup.tar.gz.html
# 6  
Old 11-11-2009
Code:
cat file.txt |xargs -n3

# 7  
Old 11-11-2009
Code:
sed ':a;N;s/\r\n/ /;ta' lsup

Code:
tr "\r\n" " " <lsup

The file is in dos format (CR-LF)
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 replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

2. Shell Programming and Scripting

Line concatenation help

please help me on this.... cat /xx.txt 2:1 2 2:2 24 8:0 0 9:0 0 Expected result would be 2:1 2 2:2 24 8:0 0 9:0 0 (4 Replies)
Discussion started by: Aditya.Gurgaon
4 Replies

3. Shell Programming and Scripting

String variable concatenation through loop problem

Hi Team!! Please can anyone tell me why the following line does not work properly? str3+=$str2 it seems that str3 variable does not keep its value in order to be concatenated in the next iteration! Thus when i print the result of the line above it returns the str2 value What i want to do is to... (8 Replies)
Discussion started by: paladinaeon
8 Replies

4. Shell Programming and Scripting

String concatenation problem

Hi there, I'm writing a basic script where I want to make a string of 2 numeric fields from a file, which I have done, but the behavior is rather confusing. I have a file of random values such as: 1 2 3 4 5 6 7 8 9 10 and my awk code is: BEGIN { FS = " " } { str = str $1 $2 } END {... (7 Replies)
Discussion started by: HMChadwick
7 Replies

5. Shell Programming and Scripting

Concatenation of a line to previous line

I need to concatenate all lines of a file into 1 line. input file containing lines like 001123456400001234563 107 001578000000000000000000000000000000000000 0000000021600 001123456912345600003 107 001578000000000000000000000000000000000000 0000000992000 i am using command echo `awk... (6 Replies)
Discussion started by: reeta_shri
6 Replies

6. Shell Programming and Scripting

Another parsing line awk or sed problem

Hi, After looking on different forums, I'm still in trouble to parse a parameters line received in KSH. $* is equal to "/AAA:111 /BBB:222 /CCC:333 /DDD:444" I would like to parse it and be able to access anyone from his name in my KSH after. like echo myArray => display 111 ... (1 Reply)
Discussion started by: RickTrader
1 Replies

7. Shell Programming and Scripting

sed problem - last line of file deleted

Hi, I am simply trying to remove the header row from a file using sed, but I'm running into strange difficulties. It seems that in addition to removing the first line, this command is also removing the last line (or more specifically, clearing the last line, since the line is still counted... (4 Replies)
Discussion started by: erichpowell
4 Replies

8. Shell Programming and Scripting

SED - editing file names (End of line problem?)

For lists in sed, to say what to replace, is this correct: I am hoping that this would recognise that either a "." is present, or that the substitution happens at the end of the line. For files with extensions , my script works perfectly. My problem is, files without extentions, i.e. . ... (1 Reply)
Discussion started by: busillis
1 Replies

9. Shell Programming and Scripting

File concatenation problem

I have written a script to find particular text files created within the last 24 hours and concatenate them all into a single concat.txt file. The problem that I am running into is that the last line of the text files do not terminate with <CR><LF> characters (as do all the other lines in each... (3 Replies)
Discussion started by: jvander
3 Replies

10. UNIX for Dummies Questions & Answers

Sed new line problem

Hi all, I've searched the web and this forum for this but not had any luck. I'm trying to use sed so when it finds a space it will insert a new line. What i have is a file containing .e.g 1 2 4 7 9 and want it to look like 1 2 4 7 9 I've tried: more test2 | sed 's/ /\\n/g'... (1 Reply)
Discussion started by: Cordially
1 Replies
Login or Register to Ask a Question