Remove newline character from file

Remove newline character from file

Post by chrish_po_wr_.. » Fri, 15 Dec 2000 02:28:46



I would like to strip the newline character from the end of each line
in a text file.

In other words, I would like:

itema
itemb
itemc

to look like:

itema itemb itemc

Is there some syntax in sed to do this?

Thanks for any ideas.
Chris

Sent via Deja.com
http://www.deja.com/

 
 
 

Remove newline character from file

Post by Gary L. Dalto » Fri, 15 Dec 2000 05:12:46


You could do it many ways, heres a couple simple ways :

1.Use good 'ol awk :
    awk '{printf "%s ",$0}'  filename   (there is a space after %s)

2. Use tr to delete the newline :
    tr -d '\012' < filename

Hope this helps,

Gary Dalton - Verizon


Quote:>I would like to strip the newline character from the end of each line
>in a text file.

>In other words, I would like:

>itema
>itemb
>itemc

>to look like:

>itema itemb itemc

>Is there some syntax in sed to do this?

>Thanks for any ideas.
>Chris

>Sent via Deja.com
>http://www.deja.com/


 
 
 

Remove newline character from file

Post by Matthew Land » Fri, 15 Dec 2000 02:25:06



> I would like to strip the newline character from the end of each line
> in a text file.

> In other words, I would like:

> itema
> itemb
> itemc

> to look like:

> itema itemb itemc

> Is there some syntax in sed to do this?

> Thanks for any ideas.
> Chris

> Sent via Deja.com
> http://www.deja.com/

Looks like you want to not STRIP a hard return but TRANSLATE it to a space.
Otherwise it would look like: "itemaitembitemc".  With that said, use the
translate command `tr`

tr '\012' ' ' <text.file >tmp.txt.file; mv tmp.txt.file text.file

 - Matt

--
_______________________________________________________________________

   << Comments, views, and opinions are mine alone, not IBM's. >>

 
 
 

Remove newline character from file

Post by Matthew Land » Fri, 15 Dec 2000 06:48:28



> You could do it many ways, heres a couple simple ways :

> 1.Use good 'ol awk :
>     awk '{printf "%s ",$0}'  filename   (there is a space after %s)

> 2. Use tr to delete the newline :
>     tr -d '\012' < filename

1 works, 2 doesn't do quite the same.  To get #2 to act like #1 you
would want:  tr '\012' ' '.  Otherwise the space between lines is lost
and they bleed together.

 - Matt

--
_______________________________________________________________________

   << Comments, views, and opinions are mine alone, not IBM's. >>

 
 
 

1. How to remove the last newline character??

Hi,

I have a process that generates a text file, but it has an extra newline
/ carrige return in it ( actually it is the 0x14 ascii character) at the
very end of the file.  I need to remove it so it does not cause problems
when it gets imported by the next process (a crappy EDI parser).

Does anyone know how to do this with regular expressions / sed, etc??
I'm on the verge of writing a C program for this but there must be an
easy solution.  I tried SED but the escape /x14 is not recognized...

Help....

David.

2. PCMCIA, ethernet, help me (please)

3. Removing newline characters

4. string comparison not working

5. summery newline to newline newline

6. rpc.portmap

7. how to read a text file and write it into a new file character by character?

8. 2.4.19-pre3 s390 memorandum

9. Removing ^M characters from a DOS text file

10. Remove non printable characters from a file

11. removing NULL CHARACTERS from ascii file

12. Removing funny files (Re: how do i remove a file with a ~ in it ????)

13. removing control characters from text files