SED - output not desired


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SED - output not desired
# 1  
Old 12-07-2010
[SOLVED]SED - output not desired

Code:
echo '0x3f 0xfa ae 0xeA' | sed '/0x[0-9a-fA-F][0-9a-fA-F]/ y/abcdef/ABCDEF/'
output:
0x3F 0xFA AE 0xEA

echo '0x3f 0xfa ae 0xeA' | sed -r '/0x[0-9a-fA-F]{2}/ y/abcdefg/ABCDEFG/'
output:
0x3F 0xFA AE 0xEA

my expected output:
0x3F 0xFA ae 0xEA

What I want to achieve is change all hexadecimals to UPPER case(only those that start with 0x), ae shouldn't be changed since it does not starts with 0x.

Why my scripts don't work?
P.S. I only want to achieve this using SED.

Last edited by kevintse; 12-07-2010 at 09:26 PM..
# 2  
Old 12-07-2010
That will not work because the pattern will select lines, not words. If you have GNU sed, you can do this:
Code:
$ echo '0x3f 0xfa ae 0xeA' | sed 's/0x\([0-9a-fA-F][0-9a-fA-F]\)/0x\U\1/g'
0x3F 0xFA ae 0xEA

# 3  
Old 12-07-2010
Hi, Scrutinizer
what does "\U" mean in the script?

Quote:
Originally Posted by Scrutinizer
That will not work because the pattern will select lines, not words. If you have GNU sed, you can do this:
Code:
$ echo '0x3f 0xfa ae 0xeA' | sed 's/0x\([0-9a-fA-F][0-9a-fA-F]\)/0x\U\1/g'
0x3F 0xFA ae 0xEA

# 4  
Old 12-07-2010
Uppercase
# 5  
Old 12-07-2010
shouldn't we \E if they are some further occurrence of " 'ae'-like " within the same line ?

...ooops forget it ... apply to matching pattern only right
# 6  
Old 12-07-2010
Code:
echo '0x3f 0xfa ae 0xeA' |awk '{for (i=1;i<=NF;i++) if ($i~/^0x/) $i="0x" toupper(substr($i,3))}1'

# 7  
Old 12-08-2010
yet another sed solution..
Code:
echo '0x3f 0xfa ae 0xeA' |sed 's/0x\(..\)/0x\U\1/g'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep -P does not capture the desired output

Hi, I'm trying to filter the following output to only display information about an alarm where the Status: corresponds to Set. -------------------------------------------------------- Description: hw_optics: RX POWER LANE-0 LOW ALARM Location: Optics0/0/0/21... (6 Replies)
Discussion started by: sand1234
6 Replies

2. Shell Programming and Scripting

Output not coming as desired.

Hi guys. I have a file containing some hosts and their IPs. host host1 192.168.2.10 host host2 192.168.2.11 host host3 192.168.2.12 I am writing a script where I want to print these values in 1 line. My script looks like RUNTIME_NODE=`cat hosts.properties | grep host` for i in... (7 Replies)
Discussion started by: Junaid Subhani
7 Replies

3. Shell Programming and Scripting

Help!! needed to get the desired output

Am in need of your help to get the desired output. nameSECURITY.SERVICES.CONFIG:GETVALUEisPrefetchedNsAccessLast2013-09-13 10:50:13 MESTsAccessTotal1sRunningcHitLastnamePUBLIC.SERVER:INVOKEisPrefetchedNsAccessLast2013-09-17 15:02:05... (5 Replies)
Discussion started by: rocky2013
5 Replies

4. Shell Programming and Scripting

Unable to obtain the desired output

Hi, I am unable to get beyond the exit function. The shell script is used to look for masked files and copy paste them to another location. Please refer to the code below for more information. Thanks Brinjit #!/usr/bin/ksh... (10 Replies)
Discussion started by: brinjit
10 Replies

5. Shell Programming and Scripting

How to grep the desired output and output to a file?

currently I have process from a raw file to this stage ALTER TABLE "EXCEL_ADMIN"."TC_TXN_VOID" ADD CONSTRAINT "PK_TC_TXN_VOID" PRIMARY KEY ("TC_TXN_IID") ALTER TABLE "EXCEL_ADMIN"."TC_TXN_AMT" ADD CONSTRAINT "PK_TC_TXN_AMT" PRIMARY KEY ("TC_TXN_AMT_IID") ALTER TABLE... (10 Replies)
Discussion started by: jediwannabe
10 Replies

6. Shell Programming and Scripting

need to get the desired output

Below is the my cide which is working fine but I am not getting the output indesired format.there is some problem in alignment.Can someone help me to correct this? if ]; then summary=$( echo -e "Please review the log file of auto coloclean utility.\n"; echo -e... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

7. Shell Programming and Scripting

Help, while loop and sed not producing desired output

Hello everyone, I need some assistance with what I thought would have been a very simple script. Purpose of Script: Script will parse through a source file and modify (search/replace) certain patterns and output to stdout or a file. Script will utilize a "control file" which will contain... (12 Replies)
Discussion started by: packetjockey
12 Replies

8. Shell Programming and Scripting

how to get desired output after redirection

hi i am running script which contains the commmnds and i am redirecting the script output to a file. like ./script 1> result.txt 2>&1 the above redirection is not working for commands when run in background in a script. but the problem here result.txt containg output which is repeated.... (3 Replies)
Discussion started by: raji
3 Replies

9. Shell Programming and Scripting

script not giving the desired output

Hi, I have a script in which an entry like this ..... FILENAME_B="PIC_${DATE}0732*.JPG" The script connects to an ATM and pull a pic file from it.The format for the file is like PIC_2008061400000001.JPG in the ATM. Means 1st 8 digit is the date(YYYYMMDD) field 2nd 8 digit means hrs... (2 Replies)
Discussion started by: Renjesh
2 Replies

10. Shell Programming and Scripting

Help me in getting the desired output

I wanted to put "|" this sign at starting and at end of every field but its not working with first field like Currently the out put is : abc | abc | abc | xyz | xyz | xyz | But I want the out put in this form: | abc | abc | abc | | xyz | xyz | xyz | plz help me. (2 Replies)
Discussion started by: akash
2 Replies
Login or Register to Ask a Question