Solved

Remove newline character from var

Posted on 2004-08-12
4
938 Views
Last Modified: 2010-04-21
Hi,
  I have a the following variable, which contains a newline character at the beginning.

  FILE_NAME=`${ORACLE_HOME}/bin/sqlplus -s   <<-EOF
                ${ORA_USER}/${ORA_PASSWORD}
                @${SQL_SCRIPT}
        EOF`


echo "#$FILE_NAME#"

returns:
#
testing.txt#

how can i get rid of it? I tried using sed and such, but i dont want echo to a file.

Thanks
0
Comment
Question by:mash79
  • 3
4 Comments
 
LVL 38

Accepted Solution

by:
yuzh earned 70 total points
ID: 11789960
use "tr"

eg:
echo "#$FILE_NAME#" | tr -d "\012"
0
 
LVL 38

Expert Comment

by:yuzh
ID: 11789965
or :

FILE_NAME=`${ORACLE_HOME}/bin/sqlplus -s   <<-EOF
                ${ORA_USER}/${ORA_PASSWORD}
                @${SQL_SCRIPT}
        EOF | tr -d "\012" `


echo "#$FILE_NAME#"

0
 

Author Comment

by:mash79
ID: 11789984
Is this correct?
I am pretty sure it is working anyway:

FILE_NAME=`echo $FILE_NAME | tr -d "\012"`

Thanks for that!
0
 
LVL 38

Expert Comment

by:yuzh
ID: 11790007
Yes!

and you are welcome!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now