openSUSE Forums > Archives > Novell Archives » Script question using sed

Go Back   openSUSE Forums > Archives > Novell Archives
Forums FAQ Members List Search Today's Posts Mark Forums Read


Novell Archives Archived content from Novell openSUSE support forums

 
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-Jan-2007, 11:23
ljungers@sbcglobal.net
Guest
 
Posts: n/a
Default Script question using sed

Hi, I'm in the process of cleaning up a few old ASCII text files that came
from another old PC. I am some what new with scripts and have checked the
web for how to use sed to strip all occurances of hex x80 - xFF in all of
the records in these files.

Here is the code I'm using, but for some reason it is not striping/dropping
the hex characters in the desired range. Exam B0 not dropped.

RemovedHexRecord=`echo $OrgRecord \
| sed -e 's/x12[89]//g' \
-e 's/x1[3-9][0-9]//g' \
-e 's/x2[0-5][0-9]//g'`

echo "$RemovedHexRecord" >> striped_hex_memo.tsv

Anyone see why this is not working. I'm on version 10.1

Thanks for any info & help
  #2 (permalink)  
Old 13-Jan-2007, 10:42
Tilman Schmidt
Guest
 
Posts: n/a
Default Re: Script question using sed

Am 12.01.2007 18:23 schrieb ljungers@sbcglobal.net:
> Here is the code I'm using, but for some reason it is not striping/dropping
> the hex characters in the desired range. Exam B0 not dropped.
>
> RemovedHexRecord=`echo $OrgRecord \
> | sed -e 's/x12[89]//g' \
> -e 's/x1[3-9][0-9]//g' \
> -e 's/x2[0-5][0-9]//g'`
>
> echo "$RemovedHexRecord" >> striped_hex_memo.tsv
>
> Anyone see why this is not working.


Sure. Your script is not searching for and removing bytes in the
hex range as you intended, but occurrences of the letter 'x'
followed by a three-digit decimal number in the range 128-259.
Try it for example with OrgRecord="blax234blux246bb" and see it
return "blablubb" in $RemovedHexRecord.

What you want is achieved more easily with the tr(1) command.
Try something like

RemovedHexRecord=`echo $OrgRecord | tr -d '\200-\377'`

(untested).

HTH
Tilman

--
Tilman Schmidt E-Mail: tilman@imap.cc
Bonn, Germany
- In theory, there is no difference between theory and practice.
In practice, there is.
  #3 (permalink)  
Old 13-Jan-2007, 15:30
ljungers@sbcglobal.net
Guest
 
Posts: n/a
Default Re: Script question using sed

> What you want is achieved more easily with the tr(1) command.
> Try something like
>
> RemovedHexRecord=`echo $OrgRecord | tr -d '\200-\377'`
>
> (untested).
>
> HTH
> Tilman
>

Thanks for the sugestion on the tr command, and I did try it the way you
illustrated above. After the script runs I used GHex to check the file that
was created and I still find hex characters that I am trying to delete,
such as Hex B0, Octal 260 still in the file.

Could it be the way the range is setup and is it a character or numeric
octal code that is used for the range check.
Thanks again

  #4 (permalink)  
Old 15-Jan-2007, 17:11
Tilman Schmidt
Guest
 
Posts: n/a
Default Re: Script question using sed

Am 13.01.2007 22:30 schrieb ljungers@sbcglobal.net:
>> Try something like
>>
>> RemovedHexRecord=`echo $OrgRecord | tr -d '\200-\377'`
>>
>> (untested).
>>

> Thanks for the sugestion on the tr command, and I did try it the way you
> illustrated above. After the script runs I used GHex to check the file that
> was created and I still find hex characters that I am trying to delete,
> such as Hex B0, Octal 260 still in the file.


Hm, works for me:

ts@gx110:~> echo $LANG
de_DE@euro
ts@gx110:~> OrgRecord=blabläblüblu
ts@gx110:~> RemovedHexRecord=`echo $OrgRecord | tr -d '\200-\377'`
ts@gx110:~> echo $RemovedHexRecord
blablblblu
ts@gx110:~> echo $OrgRecord | od -t x1
0000000 62 6c 61 62 6c e4 62 6c fc 62 6c 75 0a
0000015
ts@gx110:~> echo $RemovedHexRecord | od -t x1
0000000 62 6c 61 62 6c 62 6c 62 6c 75 0a
0000013
ts@gx110:~>

Could you post your entire script? Perhaps the reason for it not working
is to be found elsewhere than in the snippet you posted.

--
Tilman Schmidt E-Mail: tilman@imap.cc
Bonn, Germany
- In theory, there is no difference between theory and practice.
In practice, there is.
  #5 (permalink)  
Old 18-Jan-2007, 10:29
ljungers@sbcglobal.net
Guest
 
Posts: n/a
Default Re: Script question using sed

Thanks, I found what the problem was after I posted. A hidden hex value
that I did not see in the script was causing the script not to error but
run without converting.

Thanks again and yes it worked.
 

Bookmarks


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2