Disabling Backslash Interpretation with "echo -E"?
Hello All,
In a Bash Script I'm writing I have a section where I loop through a text file that was
outputted by another script. In the text file some of the strings in there are enclosed with
the BOLD "character sequences" (i.e. "\033[1m" ) and the "OFF" sequence (i.e. "\033[0m" ). Now I
am reading the file line-by-line in a while loop and saving each line into an element in an array.
What I would like to do is remove/disable these backslah escapes while saving the line from the
file into the Array element.
But it's weird, because if I run this command:
echo -E "\033[1m Hello World \033[0m"
The Output is:
\033[1m Hello World \033[0m
And running it with "-e" instead, prints: Hello World
Here is a part of my while loop and I was hoping that it would diable those backslash escapes but it doesn't.
So is there another way to read in the file or while saving the line to remove those sequences..?
I also tried adding a "sed 's/\\033\[1m//g'" to the end of the line in the while loop that assigns the line to the
FILE_Lines Array, but that didn't do anything either... I've also tried every different combination of quotes,
single and double, and still nothing...
If anyone has any suggestions, that would be great!
I'll give those a try and post back....
I had no idea though that they were called VT100 Escape Sequences... Good to know!
Thanks Again,
Matt
---------- Post updated at 09:44 AM ---------- Previous update was at 09:24 AM ----------
Hey spacebar, I gave that a try and it didn't seem to work...
Probably some character missing or something like that within the REGEX Pattern somewhere...
Hey Chubler_XL thanks again for your suggestion!
Perfect! Thanks that did the trick! That's gotta be one of the longest REGEX's I've ever seen lol...
Yeah funny you say that, I actually just noticed that a little while before I read your post... Thanks!
UPDATE:
So I'm guessing I ran into a little Perl version problem on some of our older servers...
When I ran the REGEX on the machine I'm testing this on, it worked perfectly... But when I transferred it over
to another server running Perl v5.8.2 and another with v5.8.8 it didn't do anything to the "strings" at all.
So what I did was, I tried to simplify the REGEX, because I'm guessing it matched ANY/ALL V100 Character
Sequences, but I ONLY needed to look out for the ones for BOLD"\033[1m", and the one for OFF "\033[0m"
and possibly the one for UNDERLINE "\033[4m"...
Strangely though, those escape sequences above are how you would enter them into a bash script, like this: i.e. --> echo -e "\033[1m THIS PRINTS BOLD \033[0m"
Then if I redirect the echo statement into a txt file, they show like this instead of what's above... i.e. --> "^[[1m THIS PRINTS BOLD ^[[0m"
So here's my new REGEX (also I changed the while loop to just a 'cat' command):
So far this seems to remove ALL the escape sequences from the file, so I guess
I'll use this one until or if/when something else goes wrong lol...
Thanks again you guys for your suggestions... Much appreciated!!
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)