Re: remove newlines from a file

2009-09-02 Thread Jonathan McKeown
[Agghh. To list this time]

On Tuesday 01 September 2009 20:03:19 Paul Schmehl wrote:
 I found a sed tutorial once that did this, but I can't seem to find it
 again. I have a file with multiple lines, each of which contains a single
 ip followed by a /32 and a comma.  I want to combine all those lines into a
 single line by removing all the newline characters at the end of each line.

 What's the best/most efficient way of doing that in a shell?

I'd use rs(1).

inputfile rs -C\

(The \ is escaping a space delimiter.)

unless I was worried about maximum length of output lines, in which case

inputfile xargs

Jonathan
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


remove newlines from a file

2009-09-01 Thread Paul Schmehl
I found a sed tutorial once that did this, but I can't seem to find it again. 
I have a file with multiple lines, each of which contains a single ip followed 
by a /32 and a comma.  I want to combine all those lines into a single line by 
removing all the newline characters at the end of each line.


What's the best/most efficient way of doing that in a shell?

--
Paul Schmehl, Senior Infosec Analyst
As if it wasn't already obvious, my opinions
are my own and not those of my employer.
***
It is as useless to argue with those who have
renounced the use of reason as to administer
medication to the dead. Thomas Jefferson

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: remove newlines from a file

2009-09-01 Thread Mak Kolybabi
On 2009-09-01 18:03, Paul Schmehl wrote:
 I found a sed tutorial once that did this, but I can't seem to find it
 again. I have a file with multiple lines, each of which contains a single
 ip followed by a /32 and a comma.  I want to combine all those lines into a
 single line by removing all the newline characters at the end of each line.

 What's the best/most efficient way of doing that in a shell?

Personally, I'd use:
% tr -d '\n'  inputfile

--
Matthew Anthony Kolybabi (Mak)
m...@kolybabi.com

() ASCII Ribbon Campaign | Against HTML e-mail
/\  www.asciiribbon.org  | Against proprietary extensions

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: remove newlines from a file

2009-09-01 Thread b. f.
Paul Schmehl wrote:
I found a sed tutorial once that did this, but I can't seem to find it again.
I have a file with multiple lines, each of which contains a single ip followed
by a /32 and a comma.  I want to combine all those lines into a single line by
removing all the newline characters at the end of each line.

What's the best/most efficient way of doing that in a shell?

paste(1)?

b.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: remove newlines from a file

2009-09-01 Thread Rodrigo Gonzalez

On 09/01/2009 03:03 PM, Paul Schmehl wrote:

I found a sed tutorial once that did this, but I can't seem to find it
again. I have a file with multiple lines, each of which contains a
single ip followed by a /32 and a comma. I want to combine all those
lines into a single line by removing all the newline characters at the
end of each line.

What's the best/most efficient way of doing that in a shell?



A simple solution could be using tr command

tr -d '\012'  file  output_file

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: remove newlines from a file

2009-09-01 Thread Bertram Scharpf
Hi,

Am Dienstag, 01. Sep 2009, 18:03:19 + schrieb Paul Schmehl:
 I found a sed tutorial once that did this, but I can't seem to find it 
 again. I have a file with multiple lines, each of which contains a single 
 ip followed by a /32 and a comma.  I want to combine all those lines into a 
 single line by removing all the newline characters at the end of each line.

 What's the best/most efficient way of doing that in a shell?

Probably this:

  $ echo `cat ip-file`
  $ ipline=`cat ip-file`
  $ echo $ipline | wc -l

Bertram


-- 
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: remove newlines from a file

2009-09-01 Thread Paul Schmehl
--On Tuesday, September 01, 2009 13:55:37 -0500 Mak Kolybabi m...@kolybabi.com 
wrote:




On 2009-09-01 18:03, Paul Schmehl wrote:

I found a sed tutorial once that did this, but I can't seem to find it
again. I have a file with multiple lines, each of which contains a single
ip followed by a /32 and a comma.  I want to combine all those lines into a
single line by removing all the newline characters at the end of each line.

What's the best/most efficient way of doing that in a shell?


Personally, I'd use:
% tr -d '\n'  inputfile


Personally, I like your solution.  :-)

--
Paul Schmehl, Senior Infosec Analyst
As if it wasn't already obvious, my opinions
are my own and not those of my employer.
***
It is as useless to argue with those who have
renounced the use of reason as to administer
medication to the dead. Thomas Jefferson

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: remove newlines from a file

2009-09-01 Thread Jerry McAllister
On Tue, Sep 01, 2009 at 06:03:19PM +, Paul Schmehl wrote:

 I found a sed tutorial once that did this, but I can't seem to find it 
 again. I have a file with multiple lines, each of which contains a single 
 ip followed by a /32 and a comma.  I want to combine all those lines into a 
 single line by removing all the newline characters at the end of each line.
 
 What's the best/most efficient way of doing that in a shell?

Use tr(1) something like

tr -d [\n]   inputfile   outputfile

jerry

 
 -- 
 Paul Schmehl, Senior Infosec Analyst
 As if it wasn't already obvious, my opinions
 are my own and not those of my employer.
 ***
 It is as useless to argue with those who have
 renounced the use of reason as to administer
 medication to the dead. Thomas Jefferson
 
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: remove newlines from a file

2009-09-01 Thread George Davidovich
On Tue, Sep 01, 2009 at 06:03:19PM +, Paul Schmehl wrote:
 I found a sed tutorial once that did this, but I can't seem to find it
 again.  

You're probably thinking of Useful One-Line Scripts for Sed:

http://sed.sourceforge.net/sed1line.txt

A good follow-up:

http://www.osnews.com/story/21004/Awk_and_Sed_One-Liners_Explained

 I have a file with multiple lines, each of which contains a single ip
 followed by a /32 and a comma.  I want to combine all those lines into
 a single line by removing all the newline characters at the end of
 each line.
 
 What's the best/most efficient way of doing that in a shell?

A sed solution would be

  sed -e :a -e '$!N; s/\n/ /; ta' my_file

Other (easier to remember) solutions could include:

  tr -d '\n'  my_file
  tr '\n' ' '  my_file 

  echo $(cat my_file)  # not so useless use of cat!
 
  paste -s my_file

  while read line; do 
joined=$joined $(echo $line)
  done  my_file
  echo $joined

Lots of options, of course.  Even more with Perl. 

-- 
George
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: remove newlines from a file

2009-09-01 Thread Steve Bertrand
George Davidovich wrote:
 On Tue, Sep 01, 2009 at 06:03:19PM +, Paul Schmehl wrote:
 I found a sed tutorial once that did this, but I can't seem to find it
 again.  
 
 You're probably thinking of Useful One-Line Scripts for Sed:
 
 http://sed.sourceforge.net/sed1line.txt
 
 A good follow-up:
 
 http://www.osnews.com/story/21004/Awk_and_Sed_One-Liners_Explained
 
 I have a file with multiple lines, each of which contains a single ip
 followed by a /32 and a comma.  I want to combine all those lines into
 a single line by removing all the newline characters at the end of
 each line.

 What's the best/most efficient way of doing that in a shell?
 
 A sed solution would be
 
   sed -e :a -e '$!N; s/\n/ /; ta' my_file
 
 Other (easier to remember) solutions could include:
 
   tr -d '\n'  my_file
   tr '\n' ' '  my_file 
 
   echo $(cat my_file)  # not so useless use of cat!
  
   paste -s my_file
 
   while read line; do 
 joined=$joined $(echo $line)
   done  my_file
   echo $joined
 
 Lots of options, of course.  Even more with Perl. 

Yeah, how 'bout Perl:

% perl -ne 's/\n/ /g; print;'  tests/ips.txt

:)

Steve




smime.p7s
Description: S/MIME Cryptographic Signature


Re: remove newlines from a file

2009-09-01 Thread Warren Block

On Tue, 1 Sep 2009, Steve Bertrand wrote:

George Davidovich wrote:

On Tue, Sep 01, 2009 at 06:03:19PM +, Paul Schmehl wrote:

I found a sed tutorial once that did this, but I can't seem to find it
again.


You're probably thinking of Useful One-Line Scripts for Sed:

http://sed.sourceforge.net/sed1line.txt

A good follow-up:

http://www.osnews.com/story/21004/Awk_and_Sed_One-Liners_Explained


I have a file with multiple lines, each of which contains a single ip
followed by a /32 and a comma.  I want to combine all those lines into
a single line by removing all the newline characters at the end of
each line.

What's the best/most efficient way of doing that in a shell?


A sed solution would be

  sed -e :a -e '$!N; s/\n/ /; ta' my_file

Other (easier to remember) solutions could include:

  tr -d '\n'  my_file
  tr '\n' ' '  my_file

  echo $(cat my_file)  # not so useless use of cat!

  paste -s my_file

  while read line; do
joined=$joined $(echo $line)
  done  my_file
  echo $joined

Lots of options, of course.  Even more with Perl.


Yeah, how 'bout Perl:

% perl -ne 's/\n/ /g; print;'  tests/ips.txt


perl -pe 'chomp' myfile

is somewhat easier.  Works with Ruby, too.

-Warren Block * Rapid City, South Dakota USA
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: remove newlines from a file

2009-09-01 Thread Steve Bertrand
Warren Block wrote:
 On Tue, 1 Sep 2009, Steve Bertrand wrote:
 George Davidovich wrote:
 On Tue, Sep 01, 2009 at 06:03:19PM +, Paul Schmehl wrote:
 I found a sed tutorial once that did this, but I can't seem to find it
 again.

 You're probably thinking of Useful One-Line Scripts for Sed:

 http://sed.sourceforge.net/sed1line.txt

 A good follow-up:

 http://www.osnews.com/story/21004/Awk_and_Sed_One-Liners_Explained

 I have a file with multiple lines, each of which contains a single ip
 followed by a /32 and a comma.  I want to combine all those lines into
 a single line by removing all the newline characters at the end of
 each line.

 What's the best/most efficient way of doing that in a shell?

 A sed solution would be

   sed -e :a -e '$!N; s/\n/ /; ta' my_file

 Other (easier to remember) solutions could include:

   tr -d '\n'  my_file
   tr '\n' ' '  my_file

   echo $(cat my_file)  # not so useless use of cat!

   paste -s my_file

   while read line; do
 joined=$joined $(echo $line)
   done  my_file
   echo $joined

 Lots of options, of course.  Even more with Perl.

 Yeah, how 'bout Perl:

 % perl -ne 's/\n/ /g; print;'  tests/ips.txt
 
 perl -pe 'chomp' myfile
 
 is somewhat easier.  

Nce golf...

 Works with Ruby, too.

Is Ruby Perl? ;)

Steve


smime.p7s
Description: S/MIME Cryptographic Signature