DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 22nd September 2008
bigb89 bigb89 is offline
Fdisk Soldier
 
Join Date: May 2008
Posts: 69
Default Putting Lines to Together.

Hi Guys,

Sorry if this may seem like a stupid question. I can probably find my answer on google, but I don't know exactly what I should search for. So here's what I would like to do:

Let's say I have a text file containing the following:

Hi,
my
name
is
bigb89.

What could I do to make that same file like this?:

Hi, my name is bigb89.

It doesn't matter the language I use (shell, perl, awk, sed, etc). I just would like know of a way that I can achieve that.

Regards.
Reply With Quote
  #2   (View Single Post)  
Old 22nd September 2008
anomie's Avatar
anomie anomie is offline
Local
 
Join Date: Apr 2008
Location: Texas
Posts: 445
Default

One easy way is with tr(1):
% cat text_file | tr '\n' ' '

But watch out -- that will strip off the very last newline as well (which you probably don't want).
__________________
Kill your t.v.
Reply With Quote
  #3   (View Single Post)  
Old 22nd September 2008
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default

How I would do it:

$ ex - -c '%j|wq' file'


If you want to join a specific range of lines, replace the '%' with 'startline-number,endline-number'
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
  #4   (View Single Post)  
Old 23rd September 2008
18Googol2's Avatar
18Googol2 18Googol2 is offline
Real Name: whoami
Spam Deminer
 
Join Date: Apr 2008
Location: pwd
Posts: 283
Default

%xargs echo < your_file



Have a look at this webpage for more alternative solutions:

http://linux.dsplabs.com.au/rmnl-rem...-sam-ssam-p65/
__________________
The power of plain text? It can control an entire OS
Reply With Quote
  #5   (View Single Post)  
Old 24th September 2008
bigb89 bigb89 is offline
Fdisk Soldier
 
Join Date: May 2008
Posts: 69
Default

Hi Guys,

Thank you all for all the replies!

I'll try out those commands to see how it works out!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Putting Free/Net/Open - BSDs on one HDD alpopa NetBSD Installation and Upgrading 6 23rd December 2008 08:16 PM
Deleting lines with certain letters/keywords. bigb89 Programming 4 12th November 2008 11:59 PM
Spare PC, need ideas for putting it to use TerryP Off-Topic 9 21st July 2008 02:10 PM
Adding multiple lines into file c0mrade Programming 4 7th June 2008 11:03 PM


All times are GMT. The time now is 08:59 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick