while "read" UNIDATA control character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting while "read" UNIDATA control character
# 8  
Old 07-12-2012
Try the 'file' utility.
# 9  
Old 07-16-2012
Code:
$file EIR.ENTRY2
EIR.ENTRY2: data or International Language text

I did not use any of the flags and used the /etc/magic.cat by default. Is this what you were looking for Corona?

---------- Post updated at 09:06 AM ---------- Previous update was at 08:28 AM ----------

I am running this code
Code:
#!/bin/bash
oldifs=$IFS
while read DATA
do
  echo $DATA
  for i in {1..10}
  do
    echo   "Character  ="${DATA:$i:1}
    printf "Decimal    =%d\n" "'$(echo ${DATA:$i:1})"
    printf "Octal      =%o\n" "'$(echo ${DATA:$i:1})"
    printf "Hexidecimal=%x\n" "'$(echo ${DATA:$i:1})"
    echo
  done
done < ./EIR.ENTRY2

And getting this return
Code:
FRýSCREENýBENEFIT
Character  =R
Decimal    =82
Octal      =122
Hexidecimal=52

Character  =ý
Decimal    =253
Octal      =375
Hexidecimal=fd

Character  =S
Decimal    =83
Octal      =123
Hexidecimal=53

Character  =C
Decimal    =67
Octal      =103
Hexidecimal=43

Character  =R
Decimal    =82
Octal      =122
Hexidecimal=52

Character  =E
Decimal    =69
Octal      =105
Hexidecimal=45

Character  =E
Decimal    =69
Octal      =105
Hexidecimal=45

Character  =N
Decimal    =78
Octal      =116
Hexidecimal=4e

Character  =ý
Decimal    =253
Octal      =375
Hexidecimal=fd

Character  =B
Decimal    =66
Octal      =102
Hexidecimal=42

How do I split my lines based on
Decimal =253
Octal =375
Hexidecimal=fd ??
# 10  
Old 07-16-2012
Put it into IFS?

If it doesn't work, I suspect it really isn't a single character.

It might be easier to simply replace it like you've been doing. You can also do so with nawk, probably.

Code:
nawk -v FS="ý" -v OFS="~" '{ $1=$1} 1' < data |
while IFS="~" read COL1 COL2 COL3
do
...
done

# 11  
Old 07-18-2012
I probably did this the hard way, but I iterated through the string 1 character at a time and added that character to a different string. When the character was 253 I added a ~ instead of Character 253. Very clunky, but it got the job done.
Code:
parse_STRING()
{
  oldifs=$IFS
  IFS="|"
  NUM_VAR=0
  STRING_VAR=""
  i=0
  NUM_VAR=$(printf "%d\n" "'$(echo ${DATA:$i:1})")
  while [ $i -lt $(echo ${#DATA}) ]
  do
    case $NUM_VAR in
      253 )
      STRING_VAR=$(echo $STRING_VAR"~")
      ;;
      * )
      CHAR_VAR=$(echo ${DATA:$i:1})
      STRING_VAR=$(echo $STRING_VAR$CHAR_VAR)
        CHAR_VAR=""
      ;;
    esac
    ((i++))
    NUM_VAR=0
    NUM_VAR=$(printf "%d\n" "'$(echo ${DATA:$i:1})")
  done
 DATA=$(echo $STRING_VAR) 
 IFS=$oldifs
}

NOTE: the IFS is ~
# 12  
Old 07-18-2012
So it is a single character? Are you positive?

If you could attach (not post) a sample of the data file, that could help a lot.

If it really is a single character, you can try forcing it into IFS like this:

Code:
IFS="$(printf "\375")"

But shell support for characters beyond the 0-127 range may vary.

You can also put that escape sequence into awk's -F parameter and use it that way to transform into ~.
# 13  
Old 07-18-2012
Attachment

Corona, this is the file I am trying to read and parse. I had to change it to a .txt file for the upload.
# 14  
Old 07-18-2012
Code:
$ hexdump -C EIR.TXT
00000000  0a 45 49 52 2e 45 4e 54  52 59 fd 49 4e 44 2e 52  |.EIR.ENTRY.IND.R|
00000010  41 54 45 2e 43 41 4c 43  0a 46 49 2e 45 49 52 fd  |ATE.CALC.FI.EIR.|
00000020  53 43 52 45 45 4e 2e 45  49 52 2e 45 4e 54 52 59  |SCREEN.EIR.ENTRY|
00000030  fd 42 45 4e 45 46 49 54  2e 49 4e 46 4f 0a fd fd  |.BENEFIT.INFO...|
00000040  fd fd fd fd fd fd fd fd  fd fd fd fd fd fd fd fd  |................|
00000050  fd fd fd 0a                                       |....|
00000054
$

It does indeed seem to be a single character. Whether it's ý or whatever in your character set doesn't matter too much now that we've nailed that down.

Knowing that, you can deal with it many ways.

Code:
$ tr '\375' '~' < ~/EIR.TXT  | while IFS="~" read A B C ; do echo $A ; done

EIR.ENTRY
FI.EIR

$ awk -F'\375' '{ print $1 }' EIR.TXT 

EIR.ENTRY
FI.EIR

$ IFS="$(printf "\375")"
$ while read A B C < ~/EIR.TXT ; do echo $A ; done

EIR.ENTRY
FI.EIR

$

This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

2. Shell Programming and Scripting

Read from "list1" and list matches in "list2"

I want to print any matching IP addresse in List1 with List 2; List 1 List of IP addresses; 161.85.58.210 250.57.15.129 217.23.162.249 74.76.129.101 30.221.177.237 3.147.200.59 170.58.142.64 127.65.109.33 150.167.242.146 223.3.20.186 25.181.180.99 2.55.199.32 (3 Replies)
Discussion started by: lewk
3 Replies

3. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

4. Shell Programming and Scripting

Purpose of "read" and "$END$" in ksh ?

Hi, Could anyone please shed some light on the following script lines and what is it doing as it was written by an ex-administrator? cat $AMS/version|read a b verno d DBVer=$(/usr/bin/printf "%7s" $verno) I checked that the cat $AMS/version command returns following output: ... (10 Replies)
Discussion started by: dbadmin100
10 Replies

5. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

6. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

9. Shell Programming and Scripting

how to request a "read" or "delivered" receipt for mails

Dears, I've written a script which allows me to send mails in different formats with different attaches. Now I still want to add a feature to this script. My users would like to be able to receive a "read" or "delivered" receipt for their mails. The script send mails on behalve of an specific... (1 Reply)
Discussion started by: plelie2
1 Replies
Login or Register to Ask a Question