Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 01 Sep 2009 18:35:23 -0400
From:      Steve Bertrand <steve@ibctech.ca>
To:        George Davidovich <freebsd@optimis.net>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: remove newlines from a file
Message-ID:  <4A9DA1AB.8020102@ibctech.ca>
In-Reply-To: <20090901205201.GA6126@marvin.optimis.net>
References:  <F2B402210EF1C4F7331B41C2@utd65257.utdallas.edu> <20090901205201.GA6126@marvin.optimis.net>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
George Davidovich wrote:
> On Tue, Sep 01, 2009 at 06:03:19PM +0000, 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



[-- Attachment #2 --]
0	*H
010	+0	*H
00CK9AbxIUw0
	*H
0b10	UZA1%0#U
Thawte Consulting (Pty) Ltd.1,0*U#Thawte Personal Freemail Issuing CA0
090507231610Z
100507231610Z0B10UThawte Freemail Member10	*H
	steve@ibctech.ca0"0
	*H
0
DZ杙<2IⵀfrsE6q?0.>
S@Œ!V?A\Q
r-aZ
Ōf/0{OYQhɏߴ
F_\Q0BF=<_.a*3epeY|tݼcvlҷ+@piQA{2E9WN4[Z`h6VM/zPbd(GC^K6XV4j<t-0+0U0steve@ibctech.ca0U00
	*H
æ|85aQz-*3HG		.s*Fw*`HvFw;9ytƘn0taC/:WC+LÙ{Oq 1n00CK9AbxIUw0
	*H
0b10	UZA1%0#U
Thawte Consulting (Pty) Ltd.1,0*U#Thawte Personal Freemail Issuing CA0
090507231610Z
100507231610Z0B10UThawte Freemail Member10	*H
	steve@ibctech.ca0"0
	*H
0
DZ杙<2IⵀfrsE6q?0.>
S@Œ!V?A\Q
r-aZ
Ōf/0{OYQhɏߴ
F_\Q0BF=<_.a*3epeY|tݼcvlҷ+@piQA{2E9WN4[Z`h6VM/zPbd(GC^K6XV4j<t-0+0U0steve@ibctech.ca0U00
	*H
æ|85aQz-*3HG		.s*Fw*`HvFw;9ytƘn0taC/:WC+LÙ{Oq 1n0?0
0
	*H
010	UZA10UWestern Cape10U	Cape Town10U
Thawte Consulting1(0&UCertification Services Division1$0"UThawte Personal Freemail CA1+0)	*H
	personal-freemail@thawte.com0
030717000000Z
130716235959Z0b10	UZA1%0#U
Thawte Consulting (Pty) Ltd.1,0*U#Thawte Personal Freemail Issuing CA00
	*H
0Ħ<UsUNʙZhup[v:aQP
0cZ,p+Z?qV˯<6$*+w=+>@dקe*TH<a@dr`00U00CU<0:08642http://crl.thawte.com/ThawtePersonalFreemailCA.crl0U0)U"0 010UPrivateLabel2-1380
	*H
HP.
fgCL!6-6/P p<ab:~t%Pb'qW%ݩ9 Oe_N4[5MwV!x!5$F]_eO1d0`0v0b10	UZA1%0#U
Thawte Consulting (Pty) Ltd.1,0*U#Thawte Personal Freemail Issuing CAK9AbxIUw0	+0	*H
	1	*H
0	*H
	1
090901223523Z0#	*H
	1"DO+]ub0R	*H
	1E0C0
*H
0*H
0
*H
@0+0
*H
(0	+71x0v0b10	UZA1%0#U
Thawte Consulting (Pty) Ltd.1,0*U#Thawte Personal Freemail Issuing CAK9AbxIUw0*H
	1xv0b10	UZA1%0#U
Thawte Consulting (Pty) Ltd.1,0*U#Thawte Personal Freemail Issuing CAK9AbxIUw0
	*H
[[uq
DLFU!lqsIwDόt8'([]SMH]
7giY
nН'\uPaZf䱽&t7+1
ݜ!!vӚg/ָr8"3?Wז"!5j2ӵl|[dǏʤ4DQ].8-YV1}g3#t|U3o_#', KWF\Qz
O

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4A9DA1AB.8020102>