carriage return or funky character stuck in my variables - help :)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting carriage return or funky character stuck in my variables - help :)
# 1  
Old 09-05-2008
carriage return or funky character stuck in my variables - help :)

My variables contain carriage returns... or something.

Here is the line in my xml file of interest:

<tmp>72</tmp>

And here is the line that extracts the 72 from it:

Code:
REAL=`grep '<tmp>' test.xml | sed -e 's/^ *<tmp>//' -e 's/<\/tmp>//' -re 's/(N|n|A|a|\/)/U/g'`

If echo the variable it looks just fine, but if I string a few together, the output is all messed up suggesting to me that there is an extra character in there such as a carriage return or something.

Code:
REAL=`grep '<tmp>' test.xml | sed -e 's/^ *<tmp>//' -e 's/<\/tmp>//' -re 's/(N|n|A|a|\/)/U/g'`
echo ${REAL},${REAL},${REAL}

When I run that, it returns simply:

Code:
,72

If I try to pipe it into a comma separated file, it's equally messed-up.

Code:
REAL=`grep '<tmp>' test.xml | sed -e 's/^ *<tmp>//' -e 's/<\/tmp>//' -re 's/(N|n|A|a|\/)/U/g'`
echo ${REAL},${REAL},${REAL} > test.csv

Here are the contents of test.csv:
Code:
72
,72
,72

What am I doing wrong?
# 2  
Old 09-05-2008
Seems to work for me on Linux. I get errors on OS X and OpenBSD though (doesn't understand the -re option).

What are you doing your work on?

Carl
# 3  
Old 09-05-2008
Running Debian LINUX.... the output shouldn't contain any linefeeds/returns though...

In the example above, it should return a file with a single line like this:

Code:
72,72,72

Did it do that for you?
# 4  
Old 09-05-2008
GOT IT!

Code:
REAL=`grep '<tmp>' $1 | sed -e 's/^ *<tmp>//' -e 's/<\/tmp>//' -e 's/.$//g' -re 's/(N|n|A|a|\/)/U/g'`

...you gotta love google. The solution was contained in this thread.
# 5  
Old 09-06-2008
Quote:
Originally Posted by audiophile
Running Debian LINUX.... the output shouldn't contain any linefeeds/returns though...

In the example above, it should return a file with a single line like this:

Code:
72,72,72

Did it do that for you?
Just FYI, it did do that for me (I see you have an answer but thought I'd answer you Smilie ).

I had 15 or so of the lines so I had 72 72 72 72 72, 72 72 72 72 72, 72 72 72 72 72 but all in a line.

Carl
# 6  
Old 09-06-2008
The grep is quite redundant.

Code:
sed -e '/<tmp>/!d' -e 's/^ *<tmp>//' -e 's/<\/tmp>//' -e 's/.$//g' -re 's/(N|n|A|a|\/)/U/g' "$1"

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

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

3. 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

4. Shell Programming and Scripting

Search_Replace with a Carriage Return

Hey folks, I've been working on this for some time. Seems simple, but I'm stumped. I need the following data format: New_York:Commercial Geology Geophysics Petrophysics Production_Engineering Reservoir_Engineering Pasadena:Commercial ... (5 Replies)
Discussion started by: leepet01
5 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. UNIX for Dummies Questions & Answers

carriage return and linefeed

hi can anyone please tell me the difference between carriage return, linefeed and newline ? (2 Replies)
Discussion started by: streetfi8er
2 Replies

7. Shell Programming and Scripting

Substituting carriage return followed by newline character - HELP

-------------------------------------------------------------------------------- Hi All I have a field being returned from the DB that when opened in Vi shows a ^M before the rest of the field is displayed on the next line. I need it so that the only newline character is the end of the... (14 Replies)
Discussion started by: djkane
14 Replies

8. UNIX for Dummies Questions & Answers

Substituting carriage return follwed by newline character - HELP!

Hi All I have a field being returned from the DB that when opened in Vi shows a ^M before the rest of the field is displayed on the next line. I need it so that the only newline character is the end of the line since I need to transform my file into an Excel report. Thus my idea is to... (1 Reply)
Discussion started by: djkane
1 Replies

9. Shell Programming and Scripting

Dont want carriage return

I have observed with print & echo, they produce carriage return <CR> or newline, after they display string next to them. Is there anyway to avoide these <CR> after the intended string is displayed? (3 Replies)
Discussion started by: videsh77
3 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