Home Man
Search
Today's Posts
Register

This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in the UNIX for Beginners Questions & Answers forum.

Remove a carriage return at end of variable

Tags
beginners

 

 
Thread Tools Search this Thread
# 1  
Old 11-17-2004
Remove a carriage return at end of variable

Is there a command in unix to remove a carriage return character(^M) at the end of a variable value?
# 2  
Old 11-17-2004
Code:
$ FOO="bar
> "
$ echo "$FOO"
bar

$ BAR=$FOO
$ echo "$BAR"
bar

$ BAR=`echo $FOO`
$ echo "$BAR"
bar
$


In other words, "echo" will chomp it when used without quotes.
# 3  
Old 11-17-2004
^M must not be carriage return

Before and after I tried to remove the ^M with the echo command, (per your instructions) it did not put an extra line between the output of these commands:
echo $variable
echo $variable
echo $variable
or
echo $bar
echo $bar
echo $bar

Sorry, I must have wrong, ^M must not be a carriage return, at least not to the echo command. After doing the
bar=`echo $variable`, the ^M is still there at the end of the variable bar.
# 4  
Old 11-17-2004
echo "helloworld^M" | sed 's/\^M//'
# 5  
Old 11-17-2004
If u just simply want to chop off the last character ....
do the following ....

echo "hello" | sed 's/.$//'


or u can file streams as input to sed .... ;
# 6  
Old 11-17-2004
That worked, THANKS!!!!

The sed command to remove any last character, worked like a champ! Thank you.
 

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Carriage return with cat variable Arnaudh78 UNIX for Beginners Questions & Answers 9 09-27-2016 01:37 PM
Remove carriage return and append the next line mad man Shell Programming and Scripting 16 05-12-2016 08:46 AM
Remove carriage return srvn_saru UNIX for Dummies Questions & Answers 11 04-03-2014 12:56 AM
Remove carriage return from the variable Meacham12 Shell Programming and Scripting 6 12-06-2013 06:03 AM
Awk to remove carriage return from 65th field pinnacle Shell Programming and Scripting 7 03-22-2012 11:51 AM
Remove carriage return in a record agathaeleanor Shell Programming and Scripting 10 08-03-2011 04:29 AM
Remove ^M (carriage return) with string manipulation aquila_1 UNIX for Dummies Questions & Answers 3 05-28-2011 04:24 PM
sqlplus returning value - remove carriage return '\r' - Please help sunshine1974 Shell Programming and Scripting 10 09-18-2009 08:19 PM
Insert a line including Variable & Carriage Return / sed command as Variable lowmaster Shell Programming and Scripting 2 05-19-2009 11:26 PM
To remove carriage return between the line shash UNIX for Dummies Questions & Answers 5 07-31-2007 12:12 PM


All times are GMT -4. The time now is 01:38 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password