LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-25-2004, 05:32 AM   #1
AshesOfTime
LQ Newbie
 
Registered: Nov 2004
Posts: 7

Rep: Reputation: 0
Avoid cat file1>>file2 automatic add return after file2.


file2:tftp -l file -r file -g
file1:192.168.0.1

when i cat file1>>file2 the content is:
tftp -l file -r file -g
192.168.0.1

how to put them in one line?

thanks a lot.
 
Old 11-25-2004, 06:07 AM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
You could use :
Code:
perl -pe 's/\n/ /' file1>>file2
There will be a space at the end of line tough
 
Old 11-25-2004, 06:34 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,482

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
The problem is that there is already an end-of-line in file2, so I'm not sure Cedrik's solution works either. (well, perhaps, but I avoid using perl anyway).

This is something that should work:
Code:
echo $(<file2) $(<file1) > file3

Last edited by jlliagre; 11-25-2004 at 06:35 AM.
 
Old 11-25-2004, 06:50 AM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Hey, I didn't know the use of $(<file), could you explain how it automagically remove the
\n's and replace them by spaces ? Is it the echo command that did it ?
 
Old 11-25-2004, 07:18 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,482

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
No magic here

$(<file) isn't removing the \n, it's just a shortcut to $(cat file) which itself is a better way of doing `cat file` .

It is indeed the echo command that removed the \n.
Echo is displaying each of its arguments separated by spaces and ignoring the last \n of each of it.
If you have embedded new-lines in the files, you must process them another way.
 
Old 11-25-2004, 07:27 AM   #6
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
thanks to clarify it
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding lines in file1,but not in file 2 subu_s Programming 2 12-14-2004 09:56 AM
How do I avoid booting up in X? aargh Linux - Newbie 7 10-29-2004 03:58 PM
Laptops to avoid?? morrolan Linux - Laptop and Netbook 4 01-24-2004 04:59 PM
Avoid being sniffed farpa Linux - Security 4 01-16-2004 01:14 AM
Can I get a HOW-TO avoid MCSE jdc2048 General 18 06-23-2003 03:35 AM


All times are GMT -5. The time now is 12:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration