Newbie question: delete newline character with sed

Newbie question: delete newline character with sed

Post by jose_luis_fdez_diaz_n.. » Thu, 07 Apr 2005 01:59:53



Hi,

How can I delete the newline character with sed ?

Thanks,
Jose Luis.

 
 
 

Newbie question: delete newline character with sed

Post by Heiner Steve » Thu, 07 Apr 2005 05:07:10



> How can I delete the newline character with sed ?

     tr -d '\012'

[I took the freedom of answering a "how do put a*into the wall
using a hammer" with "screw driver"]

Heiner
--
  ___ _

\__ \  _/ -_) V / -_) ' \    Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_|   http://www.veryComputer.com/

 
 
 

Newbie question: delete newline character with sed

Post by Bill Marcu » Thu, 07 Apr 2005 05:47:17




> Hi,

> How can I delete the newline character with sed ?

sed '/delete_this_newline/{N; s/\n//}'

--
"I deleted a file from my PC last week and I have just realized that I
need it. If I turn my system clock back two weeks will I have my file
back again?"

 
 
 

Newbie question: delete newline character with sed

Post by jose_luis_fdez_diaz_n.. » Thu, 07 Apr 2005 18:57:11


By the way. How can I delete a empty line ?

I have tried with:


Quote:> $//' foo

sed: command garbled: s/^\
$//

but it didn't run.

Any hint ?

Regards,
Jose Luis.

 
 
 

Newbie question: delete newline character with sed

Post by Ed Morto » Fri, 08 Apr 2005 00:48:22



> By the way. How can I delete a empty line ?

> I have tried with:


>>$//' foo

> sed: command garbled: s/^\
> $//

> but it didn't run.

> Any hint ?

> Regards,
> Jose Luis.

Bill Marcum gave you a rather large hint on April 5th. You may want to
check the responses to your original posting.

        Ed.

 
 
 

Newbie question: delete newline character with sed

Post by qazwar » Sat, 09 Apr 2005 01:20:30


Remember that sed has more commands in it than just "s" for
substitution:

sed '/^$/d'

Any line that matches the pattern "/^$/" (blank lines) will be deleted
from the input. If you want to delete lines that may contain spaces and
tabs, but nothing else, you need to use this:

sed '/^[ \t]*$/d

The "\t" doesn't work with all versions of sed, so you might need to
use a real tab character instead.

 
 
 

Newbie question: delete newline character with sed

Post by Ed Morto » Sat, 09 Apr 2005 04:10:34



> Remember that sed has more commands in it than just "s" for
> substitution:

> sed '/^$/d'

> Any line that matches the pattern "/^$/" (blank lines) will be deleted
> from the input. If you want to delete lines that may contain spaces and
> tabs, but nothing else, you need to use this:

> sed '/^[ \t]*$/d

> The "\t" doesn't work with all versions of sed, so you might need to
> use a real tab character instead.

The OP didn't say he wanted to delete blank lines, he said he wants to
delete newline characters.

        Ed.

 
 
 

Newbie question: delete newline character with sed

Post by John Savag » Sat, 09 Apr 2005 10:41:16



>By the way. How can I delete a empty line ?

To delete every empty line: sed '/^$/d' foo

:I have tried with:
:

:> $//' foo
:sed: command garbled: s/^\

The default action of sed is to load one line at a time (excluding that
line's own end-of-line terminating character) into the pattern space and
to edit the content of that line according to your script. This means
there is NO newline character to be found in the pattern space. So even
when you believe you have worked out the right command to delete a newline
character, there actually is not one to be found so none will be deleted.

Only through use of the N and H or G commands can a newline character exist
in the pattern space, but these are hardly within the province of a newbie.
--
John Savage                   (my news address is not valid for email)

 
 
 

1. Using sed to replace a newline character??

Hello,

I am having trouble getting sed to substitute a space for newline characters
in a file.

Basically, I have a file that looks like this:

fred
jane
ted
susan
harold

And I want it to look like this:

fred jane ted susan harold

You see I want to simply replace all newline characters with spaces.  I have
tried everything!  The following doesn't work:

sed s/\n/' '/ file > newfile

I don't understand what is wrong!  Please help!!

Thanks,

Andy

2. Can't analyse crash dump...

3. deleting newline characters

4. Adaptec 2842

5. Searching and replacing for a string with a newline character with sed.

6. un*x vs. unix

7. deleting newlines in sed (or awk or whatever)

8. Wath app must be opened

9. Q: sed: Deleting three characters after string?

10. sed: how to delete string of spaces before a CR character?

11. another sed problem: sed and newline chars

12. sed: delete different characters

13. newline character question