Visit Our UNIX and Linux User Community

Screwy Characters or Inferior Command?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Screwy Characters or Inferior Command?
# 1  
Old 08-06-2009
Screwy Characters or Inferior Command?

OK, I have a script ( which contains some variables somewhere in it:


When I do this piped command:
grep SomeVariable= | cut -d"=" -f2

I get this output:

However, when I do this:
echo `grep SomeVariable= | cut -d"=" -f2`

I just get

With some of my better scripts, I get this correct output:

someValue someValue2

When I make use of this info, it somehow manages to toss in some "\b" characters and screws up the output of what I was trying to do. One person suggested that this may be due to the script being written on a windows machine and then being SFTPed into Linux. I've run vim and I can't find a single character that's screwed up. I can't use dos2unix because I don't have permission to install it. Can anyone please let me know of a different command that I can do to make this spaced values effect without the other values being chopped off? I'll be doing this to pass these values into an array.

All responses will be greatly appreciated.
# 2  
Old 08-06-2009

:set ff=unix
# 3  
Old 08-06-2009
Originally Posted by mrwatkin
Can anyone please let me know of a different command that I can do to make this spaced values effect without the other values being chopped off? I'll be doing this to pass these values into an array.
You can use Perl. After you SFtp the script to Linux and before you run the "grep" command, do this -

perl -pi.bak -e 's/\r//g'

The weird output of the grep command is due to the "carriage return" character "\r" (ASCII decimal 13), which moves the cursor to the first position of the same line thereby forcing the 2nd line to overwrite the first line. (The "\r" comes from files created in Windows.)

$ echo `grep SomeVariable= | cut -d"=" -f2`
$ echo `grep SomeVariable= | cut -d"=" -f2` | od -bc
0000000 163 157 155 145 126 141 154 165 145 015 040 163 157 155 145 126
          s   o   m   e   V   a   l   u   e  \r       s   o   m   e   V
0000020 141 154 165 145 062 015 012
          a   l   u   e   2  \r  \n

So -

$ # Using Perl to remove the carriage return characters
$ perl -pi.bak -e 's/\r//g'
$ echo `grep SomeVariable= | cut -d"=" -f2`
someValue someValue2

The ".bak" backs up your script before applying the changes.

# 4  
Old 08-07-2009

Darn those \r characters! Found em. Thanks again.

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using CURL command with special characters in URL

Hi. I 'm trying to hit a REST api and retrieve a JSON feed, and the URL has special characters in it. Something like: Example Domain The below curl command is failing curl -X GET saying bad command at id=1001 I am going to use this as part... (3 Replies)
Discussion started by: kumarjt
3 Replies

2. Shell Programming and Scripting

Ps command and awk - shorten characters

ps -e -o pcpu -o pid -o user -o args | sort -k 1 | tail -6r %CPU PID USER COMMAND 0.3 223220 root /usr/tivoli/tsm/client/ba/bin/dsmc sched 0.2 411332 root /usr/sbin/syslogd 0.1 90962 root /usr/sbin/syncd 60 0.0 10572 root -ksh 0.0 94270 root -ksh ... (4 Replies)
Discussion started by: SkySmart
4 Replies

3. Shell Programming and Scripting

Special characters in command arguments

Hey Guys, I have a program that populates a database based on input I feed it. so it would look like: cmd arg1 arg2 ... argN Now some of the arguments have special characters in them so I wrote a small script to pull the args and wrap them in quotes ('arg'). The problem is sometimes... (10 Replies)
Discussion started by: aaron0001
10 Replies

4. UNIX for Dummies Questions & Answers

sed command to remove characters help!

I am trying to analyse a large file of sequencing data, example of first 10 lines below, @HWUSI-EAS656_0044_FC:7:1:2447:1039#GCAATT/1 GNCTATGGCTTGCCGGGCTCAGGGAAGACAATCATAGCCATGAAAATCATGGAAAAGATCAGAAAAACATTTCAA +HWUSI-EAS656_0044_FC:7:1:2447:1039#GCAATT/1... (1 Reply)
Discussion started by: Adeleh
1 Replies

5. Shell Programming and Scripting

Using awk with the date command and escape characters

I have a file that is a log file for web traffic. I would like to convert the timestamp in it to unix time or epoch time. I am using the date command in conjunction with awk to try to do this. Just myfile: 28/Aug/1995:00:00:38 1 /pub/atomicbk/catalog/home.gif 813 28/Aug/1995:00:00:38 1... (3 Replies)
Discussion started by: jontjioe
3 Replies

6. Shell Programming and Scripting

Grep command to count characters

I have a file that I need to count the number of "Y"s in the file, but just the "Y"s that fall between certain columns. Like: file1: 1234567890123456789012345 BBBBBBYBBBBYBBYBBYBBYBBB I want to count the 'Y's between 17 and 21 = 2 "Y"s Thanks (12 Replies)
Discussion started by: jbt828
12 Replies

7. Shell Programming and Scripting

exclude characters in echo command please help

Hi all, I wrote one code and i face some difficulties to exclude some characters from the echo command more specifically the last command is echo $a "${RESULT}" >> results_data_srcip the results which i have taken are: nfcapd.200908250000 -.352228 nfcapd.200908250005 -.345085 ... (4 Replies)
Discussion started by: draxmas
4 Replies

8. Shell Programming and Scripting

get characters from output of a command in a variable

Hi, i have two questions, I am new to programming 1. I have an output of a command and i want to get some specific part of it in a variable. i am trying sr=`some comand xyz| grep 'Last Changed Rev:' | cut -c19-` now variable sr gets a end of line character at end. output of the command... (3 Replies)
Discussion started by: muaz
3 Replies

9. UNIX for Dummies Questions & Answers

Sed command with characters

Hi everyone, I hope that someone can help me out: In the following line: PRIHDR;2809999444;2007 6.1;20070423;9;;4021473000003;;4021473000003;8714231530688;EUR;; The output should be: PRIHDR;2809999444;2007 6.1;20070423;4;;4021473000003;;4021473000003;8714231530688;EUR;; I've tried... (7 Replies)
Discussion started by: IHulky
7 Replies

10. UNIX for Dummies Questions & Answers

Command to get only the Three Characters of the Month

Hi, Please let me know if I can format the output of the date command to three character month name. For example,if I type date and enter, it should give the Month name in the following format: Jan or Feb or Mar etc i.e, only the first three characters of the month name. Please respond... (2 Replies)
Discussion started by: prashanth_gs
2 Replies

Featured Tech Videos