LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using cat, tr and echo (https://www.linuxquestions.org/questions/linux-newbie-8/using-cat-tr-and-echo-416448/)

AlexSapec 02-17-2006 06:49 AM

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

nx5000 02-17-2006 07:05 AM

Tr is too limited, better use sed:
replace by:
Code:

sed 's/\\$/\\\n/g'

satinet 02-17-2006 07:18 AM

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

satinet 02-17-2006 07:21 AM

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

i sometimes refer to this....

AlexSapec 02-17-2006 07:31 AM

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.

satinet 02-17-2006 07:51 AM

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??

AlexSapec 02-17-2006 09:27 AM

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.

muha 02-17-2006 10:03 AM

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


All times are GMT -5. The time now is 05:48 AM.