Text Highlighting Discrepancy, Caused by SED?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Text Highlighting Discrepancy, Caused by SED?
# 1  
Old 01-30-2012
Text Highlighting Discrepancy, Caused by SED?

> reverse=`tput rev`
> revert=`tput sgr0`

> var="This is some note."
> echo $var
This is some note.

> var2="This is ${reverse}some${revert} note."
> echo $var2
This is some note.

> var3=$(echo $var | sed 's/some/${reverse}some${revert}/g')
> echo $var3
This is ${reverse}some${revert} note.

An alternative to var3 also doesn't work:
> var3=$(echo $var | sed 's/some/`tput rev`some`tput sgr0`/g')
> echo $var3
This is `tput rev`some`tput sgr0` note.

Whats more, I can take the output from my 2nd var3 and do as follows, which works:
> var4="This is `tput rev`some`tput sgr0` note."
> echo $var4
This is some note.

I am working in KSH88. The red text is reflective of the reversed text I see in my terminal window.

Can anyone explain to me why hand creating the text string works but when I create the exact same text with a sed statement the echo does not render the text correctly?

Many Thanks!
# 2  
Old 01-30-2012
Your sed expression is surrounded by single quotes. Nothing expands in single quotes.

Code:
$ VAR="123"

$ echo '${VAR}'
${VAR}

$ echo "${VAR}"
123

$

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 01-30-2012
Excellent! Changed the ' to " on the sed statement and viola. Many thanks!

Although I'm unsure how the command line knows the difference between the text created by me and the sed statement. They are identical at the point the be echo'd aren't they? Is there a hidden character in there?
# 4  
Old 01-31-2012
Quote:
Originally Posted by adamreiswig
Although I'm unsure how the command line knows the difference between the text created by me and the sed statement.
It's nothing to do with that. It's the difference between things in single quotes and things in double quotes. Things in single quotes never expand -- ever. That's why the shell has them.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk output discrepancy

I noticed a discrepancy while running AWK on different platforms/versions: SunOS $ echo "78" | awk '{ printf "%c\n", $0 }' N $ awk 'BEGIN{ printf "%c\n", "78" }' /dev/null N Linux / HP-UX $ echo "78" | awk '{ printf "%c\n", $0 }' N $ awk 'BEGIN{ printf "%c\n", "78" }' /dev/null 7 Can... (4 Replies)
Discussion started by: Yoda
4 Replies

2. OS X (Apple)

RAM Usage discrepancy

Hey there! I'm a new user here who registered because I couldn't get these kind of questions answered in the place I directly com from. :o I've found a discrepancy in total RAM used and I can't figure out why it is. My only guess is there are some RAM used by some stuff impossible to identify,... (2 Replies)
Discussion started by: dasx
2 Replies

3. Solaris

Sun X4170 M2 RAM discrepancy

Hi all, We are seeing an odd problem on one of our new servers. It seems to be reporting 4MB less RAM than is installed: # prtconf | grep Mem Memory size: 32764 Megabytes Our other servers for example shows none missing: # prtconf | grep Mem Memory size: 32768 Megabytes Both... (5 Replies)
Discussion started by: wmd
5 Replies

4. Linux

what caused no event found?

I tried to run nohup command line on my Linux server to connect to a remote server, then execute Oracle binary to run a process at background. My Linux information looks like this: oracle@myserver:/opt/oracle/scripts $ uname -a Linux myserver.domain.com 2.6.18-194.32.1.0.1.el5 #1 SMP Tue Jan 4... (1 Reply)
Discussion started by: duke0001
1 Replies

5. Shell Programming and Scripting

AWK: Discrepancy in numeric output

During a file-system cleanup I noticed a strange behavior of awk (HP-UX 11iv3 / IA64). When summing up the size of files in one directory it gives different numbers when using print as opposed to printf: find . -type f -name '*.dmp.Z' -mtime +35 -exec ls -l {} \+ | \ awk 'BEGIN{ OFMT="%f" } {... (1 Reply)
Discussion started by: pludi
1 Replies

6. Solaris

Discrepancy in /var/adm/messages

A fresh installation was done in a machine of name arenal1 on Feb 26. But in the /var/adm/messages of the machine, there are messages having date Nov 12. Also the name of the machine is also different in the messages. Can anyone please tell me the reason for this discrepancy. (15 Replies)
Discussion started by: sundar3350
15 Replies

7. Post Here to Contact Site Administrators and Moderators

Unsure what caused an infraction on my account.

Hey everyone. I wasn't sure what it meant when my profile said it had 1 infraction against it, so I thought I'd check it out. Unfortunately, I can't find the post in question. The date from the post in question is 07-09-2008 at 04:24 AM, but from what I can tell is marked as 'private'. I'd... (2 Replies)
Discussion started by: glen.barber
2 Replies

8. Shell Programming and Scripting

syntax error near unexpected token...what caused?

Dear all, When I tried to run receive.sh,it returned following errors. syntax error near unexpected token `do #!/usr/bin/ksh GlobalValueReceive=r GlobalValueWorking=w GlobalValueTemp=t $exec 0<Property while read LineInProperty do if then $GlobalValueReceive =... (8 Replies)
Discussion started by: joshuaduan
8 Replies

9. Shell Programming and Scripting

"highlighting the text in ur output"

Hi, Can anyone tell me..how to highlight a particular part of ur output text in shell programming..say,if all the o/p is against black bground,i need some text to be against white bground.. eg..You can see some text highlighted in man pages .Right?? But how ll you do that. Thanx (6 Replies)
Discussion started by: sakthi.abdullah
6 Replies

10. UNIX for Dummies Questions & Answers

NIS login discrepancy

I have a query in relation to a couple of machines I have set up. We will call them machine SUN and HPUX and they are running those operating systems respectively. The SUN machine is acting as an NIS server and the HPUX machine as an NIS client. Now the HPUX machine also has a an auto mounted file... (11 Replies)
Discussion started by: Henrik
11 Replies
Login or Register to Ask a Question