Carriage return with cat variable


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Carriage return with cat variable
# 1  
Old 09-27-2016
Carriage return with cat variable

Hi,

I wish to know how to works the carriage return with cat.. As a picture often speaks better than words, my code below :
Code:
#te=`cat text.txt` (I tried this, but the same..)
te=$(cat text.txt)

echo $te

My file text.txt below:
Code:
BLABLABLABLABLALBLA

BLABLABLABLABLALBLA

BLABLABLABLABLALBLA

The Output :
Code:
BLABLABLABLABLALBLA BLABLABLABLABLALBLA BLABLABLABLABLALBLA

I tried "\n" into text.txt, the same.. Please who can help me ?

Thanks by advance. Smilie
# 2  
Old 09-27-2016
where are you trying? on a PC after having copied the file in Widows?
because if your txt file has 3 line cat will display 3 lines... ( in other words it looks like a DOS conversion with Line feed you are after...
Here on a debian:
Code:
"blabla.txt" [New File] 4 lines, 40 characters written
xns:/home/vbe $ cat blabla.txt
blablalba
blablalba
blablalba
blablalba

# 3  
Old 09-27-2016
On linux

---------- Post updated at 12:06 PM ---------- Previous update was at 12:01 PM ----------

Yes me too, but I do :
Code:
echo $te

The output doesn't the carriage return Smilie
# 4  
Old 09-27-2016
Don't mix up "carriage return" with "\n" (which is "line feed"). When expanding an unquoted variable (with the default IFS variable), ALL whitespace will be replaced by the first IFS character, usually a space. That's why the "\n" is "lost"...
This User Gave Thanks to RudiC For This Post:
# 5  
Old 09-27-2016
I want to put (cat file.txt) because after I use the variable for send an email with sendemail example :
Code:
/usr/bin/sendemail -f $sender -t $recipient -u $subject -m $te -s $server

# 6  
Old 09-27-2016
Did you try?:
Code:
 echo "$te"

This User Gave Thanks to vbe For This Post:
# 7  
Old 09-27-2016
Quote:
Originally Posted by RudiC
Don't mix up "carriage return" with "\n" (which is "line feed"). When expanding an unquoted variable (with the default IFS variable), ALL whitespace will be replaced by the first IFS character, usually a space. That's why the "\n" is "lost"...
mhhh... I understand, there is another solution?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Remove carriage return

I need to remove the carriage return comes inbetween the record. Need to have CR only at the end. I used the below command. tr -d '\n' < filewithcarriagereturns > filewithoutcarriagereturns But its removing all the CR and giving one line output. Input File: 12345 abcdegh... (11 Replies)
Discussion started by: srvn_saru
11 Replies

2. Shell Programming and Scripting

Remove carriage return from the variable

Hi, I try to handle very large numbers with a bash script. I run ssh command in a remote server and store the output in a local variable. But this output contains a return carriage at the end. So I try to remove it by tr But I can't figure out the right notation with printf. So my problem... (6 Replies)
Discussion started by: Meacham12
6 Replies

3. Shell Programming and Scripting

Substitute \n with carriage return

Hello all, I've a flat file in the following format: AB\001\CDED\001\ABC\001\nEG\001\HIJF\001\EFG\001\nHI\003\HIUL\003\HIJ\003 And I want to substitute \n with the carriage return. Any help is appreciated! Regards, - Seth (8 Replies)
Discussion started by: sethmj
8 Replies

4. Shell Programming and Scripting

Carriage return ksh

Hello, How do i usecarriage return in ksh. I want to do an echo "bla bla" and another echo "bla bla" will appear and replace the first echo on screen. I tried: until ; do echo "bla bla \r" done please advice. Thanks. (3 Replies)
Discussion started by: LiorAmitai
3 Replies

5. Shell Programming and Scripting

2 carriage return within a record

Hi all, need your help in replacing carriage return in a record. Input: col1|col2|col3|col4|col5|col6|col7|col8|col9|col10 1|aa|bb|cc|dd|eee eee|ff|ggggg|hh hhh|iii 2|zz|yy|xx|ww|vv|uu|tt|ss|rr Output: col1|col2|col3|col4|col5|col6|col7|col8|col9|col10... (12 Replies)
Discussion started by: agathaeleanor
12 Replies

6. Shell Programming and Scripting

A variable is including the Carriage Return char...

Hi all, I'm reading a file with this layout: First_Col Second_Col The Second_Col has values as 1000, -1, 10, 43... While reading the file I'm getting the second column value with awk command, but it is including the CR control char. do item_saved=`echo $b | awk '{print... (4 Replies)
Discussion started by: mrreds
4 Replies

7. Shell Programming and Scripting

sqlplus returns leading carriage return into a variable

I am trying to generate some scripts to help manage an Oracle database. When I check the value returned from Oracle it has a leading carriage return in the variable. Is there a way to prevent this? Is there a way to easily strip out the carriage return. See code and output below. ... (7 Replies)
Discussion started by: Panzer993
7 Replies

8. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

9. UNIX for Dummies Questions & Answers

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? (5 Replies)
Discussion started by: flagship99
5 Replies

10. Shell Programming and Scripting

Capture carriage return.

I try to test the carriage return in a variable. $ LENGTH=`expr $VARIABLE : ".*"` will return the length of the variable. But this doesn't work if $VARIABLE has zero length. Any help will be well appreciated. Thanks in advance. Giovanni (4 Replies)
Discussion started by: gio123bg
4 Replies
Login or Register to Ask a Question