Sponsored Content
Top Forums Shell Programming and Scripting Disabling Backslash Interpretation with "echo -E"? Post 302688819 by mrm5102 on Monday 20th of August 2012 10:49:36 AM
Old 08-20-2012
Hey 244an, thanks for the reply...
Thanks for the insight..!

Sorry I'm not exactly sure what your asking?
Are you saying that I "shouldn't" be able to remove these character sequences with the REGEX,
because "^[" is NOT literally a "^" or a "[", but "literally" an "ESC"...?

If that's what your saying, then I'm not sure why it would be working then..? Maybe it's the way I'm
writing the output to the file...


EDIT:
Ok... I see what your saying now. I just checked the output file in VI and you were right about the "^[", if
I scroll through the file it skips over the "^[" as if it were one character. I see what you mean by it being
weird that it actually works.!?

Maybe it has something to do with the "cat -v" command. The "-v" or aka "--show-nonprinting" will use ^
and M- notation, except for LFD and TAB. I'm assuming this probably is the reason why it's working..?

Here is my code for reading the file and removing those sequences:
Code:
EXPECT_OUTPUT="/path/to/output/file.txt"

IFS='
'
### If the output file exists, then read in the Output file and split it line-by-line...
if [ -e $EXPECT_OUTPUT ]
 then
    TEMP_Lines=( $(cat -v "$EXPECT_OUTPUT" | sed 's/\^\[\[[0-9]m//g') )
fi

Now from the command line if I run "cat myOutputFile.txt" I get:
Quote:
DATE: Monday 08-20-2012
TIME: 10:15 AM
REMOTE_HOST: myHost-vm (192.168.5.101)

Getting the Status of the NRPE Daemon:
- The NRPE Daemon is Running with PID=2532
Then running "cat -v myOutputFile.txt":
Quote:
^[[1mDATE:^[[0m Monday 08-20-2012
^[[1mTIME:^[[0m 10:15 AM
^[[1mREMOTE_HOST:^[[0m myHost-vm (192.168.5.101)

Getting the Status of the NRPE Daemon:
- The NRPE Daemon is Running with ^[[1mPID=2532^[[0m
Soo I'm not exactly sure why it's working, but I just know i'm glad it does lol...
But anyway thanks again for your reply...


Thanks Again,
Matt
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Interpretation of "echo $-"

I am running Solaris 10. Can someone help me interpret the output from "echo $-"? Interactively, the output is: ism From within a cron job, the output is: xh Why are they different? Can someone point me to the appropriate documentation? Thanks, J (1 Reply)
Discussion started by: shew01
1 Replies

2. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

3. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

4. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. AIX

echo $varibla | mail -s "subject" "xxx@xxx.com" not ruuning as expected

Hi Folks, As per the subject, the following command is not working as expected. echo $variable | mail -s "subject" "xxx@xxx.com" Could anyone figure it out whats wrong with this. I am using AIX box. Regards, (2 Replies)
Discussion started by: gjarms
2 Replies

7. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

8. Shell Programming and Scripting

sed command escaping backslash "/"

Hello friends/'unix experts', i have a file as below cat sample.txt satish /rakesh/ sandhya /sandeep/ i have to replace /rakesh/ with rakesh, how can i do it with sed, i tried below code but its throwing errors sed -e 's/'"\(/rakesh/)\"'/\1rakesh/g' sample.txt ... (1 Reply)
Discussion started by: only4satish
1 Replies

9. Shell Programming and Scripting

Escaping backslash and asterisk in egrep to match "\*"

So far what i've got is egrep '^(\\)\*$'No luck. I've searched the web and not much luck. I know about the escape character \ but its confusing to figure out how to use it to match a backslash and use it to escape the asterisk also. Any ides? Thanks! (8 Replies)
Discussion started by: matthewfs
8 Replies

10. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
All times are GMT -4. The time now is 02:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy