LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 02-17-2006, 07:49 AM   #1
AlexSapec
LQ Newbie
 
Registered: Feb 2006
Posts: 5

Rep: Reputation: 0
Unhappy Using cat, tr and echo


Hello everyone. I'm fairly new to Linux/Unix and i'm still dealing with the (i presume), easier parts of the console. I'm trying to do the following:


TEXTO_RC_LOCAL=`cat -E /etc/rc.local | tr "$" "\\n"`
echo -e $TEXTO_RC_LOCAL


The problem is that the echo does not recognize the newlines. When i do:


cat /etc/rc.local


it works fine and prints the newlines in the console. I'm trying -E to use $, and then tr to replace that with newlines. So far, no luck. Could anyone give me a hand with this problem? Maybe this is not the correct way to do it, in that case, i would appreciate some advice on how to do these kind of things.

Thanks very much

Alejandro
 
Old 02-17-2006, 08:05 AM   #2
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 53
Tr is too limited, better use sed:
replace by:
Code:
sed 's/\\$/\\\n/g'
 
Old 02-17-2006, 08:18 AM   #3
satinet
Senior Member
 
Registered: Feb 2004
Location: England
Distribution: Slackware 11, Sabayon 3.1
Posts: 1,464

Rep: Reputation: 46
what output are you actually hoping to acheive here?

if you want to change the end of line characters do:

what happens if you try this:

sed -e 's/$/\\n/g' /etc/rc.local
 
Old 02-17-2006, 08:21 AM   #4
satinet
Senior Member
 
Registered: Feb 2004
Location: England
Distribution: Slackware 11, Sabayon 3.1
Posts: 1,464

Rep: Reputation: 46
take a look at http://www.student.northpark.edu/pem...d/sed1line.txt

i sometimes refer to this....
 
Old 02-17-2006, 08:31 AM   #5
AlexSapec
LQ Newbie
 
Registered: Feb 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Smile Thanks so much, people...

Actually, what i am trying to do is a bash script that installs Kasenna Mediabase, along with ALOT of other things (one of them being the app i profesionally program). To do that, i must be able to edit some files (/etc/rc.local) throught the bash script (risky, i know, but has to be done this way). I have never used sed, but i can see it's the way to go, so i will make it a point to learn this.
Thanks very much to everyone for your VERY FAST answers. It's really nice to get this much help on such a difficult topic (at least for me). Rest assured, when i get to be the LinuxGeek(tm), i will help others just as much.
 
Old 02-17-2006, 08:51 AM   #6
satinet
Senior Member
 
Registered: Feb 2004
Location: England
Distribution: Slackware 11, Sabayon 3.1
Posts: 1,464

Rep: Reputation: 46
are you implying i'm a geek?!?!

lol

in addition to sed i highly recommend coming to terms with its bedfellow 'awk'.

using sed and awk together can do a great deal of useful things. i also believe the gnu version of sed allows a "-i" option to edit files in place. i am used to the unix version which sends the edited file to stdout.

did it actually work btw??
 
Old 02-17-2006, 10:27 AM   #7
AlexSapec
LQ Newbie
 
Registered: Feb 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Well, i finished working for this week (on Fridays i get home early), so i plan on learning sed and awk this weekend and then i will tell you... I use Windoze at home (i know, crucify me), but i plan to switch to a Dual-Boot soon.

Oh, and "geek", was meant as a compliment, as in "he knows so much 'bout Linux, he's a geek". I'm not English-native, so i really don't know how appropiate this term is in the situation i say.

Last edited by AlexSapec; 02-17-2006 at 10:28 AM.
 
Old 02-17-2006, 11:03 AM   #8
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
you might want to check the lq wiki here ~> http://wiki.linuxquestions.org/wiki/Sed
and the 'home' of sed ~> http://sed.sourceforge.net/ for lot's of examples and faqs
 
  


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
Kphone echo (echo echo) scabies Linux - Software 0 10-18-2004 03:59 PM
crontabbed shell script, trying to echo/cat something zaubara Programming 2 06-13-2004 08:18 PM
Cat ... Beuzekom Linux - Newbie 4 01-19-2004 06:32 PM
Echo /devPrinting doesn't work, echo /usb/lp0 works, Testpage works, Printing doesn't Hegemon Linux - General 3 08-15-2002 02:13 PM
regarding cat gui10 Linux - Security 6 12-07-2001 09:09 PM


All times are GMT -5. The time now is 03:04 PM.

Main Menu
Advertisement
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