Visit Our UNIX and Linux User Community

Using subsring in ksh93 - How to stuff a byte back in

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using subsring in ksh93 - How to stuff a byte back in
# 1  
Old 03-25-2006
Using subsring in ksh93 - How to stuff a byte back in

#!/bin/ksh93                 # set to ksh93 so we can use substring 
cat "file" |
while IFS=\n read I          # read the next record into I
do                           # do not parse out blanks, tabs in the record by setting IFS to newline char only
  D1=${I:27:1}               # isolate byte 27 into D1
  if [[ "$D1" = " " ]]       # if byte 27 = a blank
     ${I:27:1}="-"           # change byte 27 to a dash "-"   <-- ### WARNING, this syntax is invalid ###          
    :                        # no change to byte 27 
  print "$I"                 # write out record  

A question on the above code:
  • is there a simple way (using substring) to modify byte 27 using the above example ?
FWIW, I wasn't able to come up with any syntax that would allow me to substring the desired change back into the record. I had to use other techniques to accomplish the same thing..... but was hoping the experts here might see something simple, that no doubt I missed. Thx for any help.

Last edited by The Doctor; 03-26-2006 at 01:31 AM.. Reason: changed commas to colons in ${I:27:1}
# 2  
Old 03-25-2006
You seem to have some mutant form of ksh93. That syntax is not legal. You should be using colons, not commas...
$ x=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLNMOPQRSTUVWXYZ
$ echo $x
$ echo ${x,27,1}
/opt/ksh93/bin/ksh: syntax error: `,' unexpected
$ echo ${x:27:1}
$ echo ${.sh.version}
Version M 1993-12-28 m+

Would you do an "echo ${.sh.version}" and post the results? Also what system are you using? I hesitate to present my solution since I cannot predict the behavior of your shell, but here it is anyway....
$ x=${x:0:27}'-'${x:28}
$ echo $x

# 3  
Old 03-26-2006
Originally Posted by Perderabo
That syntax is not legal. You should be using colons, not commas...
ooops, yes I screwed up..... you are correct.... the commas should be colons. I'll try to edit my original post & fix that. I wrote my post from memory (not a C&P of my original script) and messed the substring syntax up. Sorry for the confusion this caused.

thx for taking the time to answer.... your solution -->
is simple & very straightforward. Just what I was looking for. Thx again.

Last edited by The Doctor; 03-26-2006 at 01:41 AM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #667
Difficulty: Easy
IEEE 802 is a family of IEEE standards dealing with local area networks and metropolitan area networks.
True or False?

10 More Discussions You Might Find Interesting

1. AIX

Ksh93/AIX compatibility

Hi everyone ! Im trying to know from wich version of AIX KSH93 is available ? Internet tell me 6.x and 7.x AIX are available, bue what about 5.x ? Is KSH93 available on AIX 5.x ? Is it the same way to manipulate variables as KSH93 on 7.x ? Thanks for your support and have a nice day ! (2 Replies)
Discussion started by: majinfrede
2 Replies

2. UNIX for Advanced & Expert Users

Ksh93 on Linux compatible with ksh93 on AIX

Hi Experts, I have several shell scripts that have been developed on a Linux box for korn ksh93. If we want to run this software on an AIX 6.1 box that runs ksh88 by default can we just change the she-bang line to reference /bin/ksh93 which ships with AIX as its "enhanced shell" to ensure... (6 Replies)
Discussion started by: Keith Turley
6 Replies

3. Shell Programming and Scripting

Solaris 11 ksh93 if condition issue

Solaris 11 ksh93 if condition issue Has anyone run into issues with Solaris 11 with ksh93 if condition where it intermittently return wrong return code? We did not see this issue in Solaris 10 with ksh88 Any thoughts? Thanks! Solaris version: SunOS t52-ccc-28 5.11 11.2... (4 Replies)
Discussion started by: nugent
4 Replies

4. Shell Programming and Scripting

ksh93 different results using -x option

This problem seems to be specific to ksh93. If you run with set -x some scripts don't work properly. For example: $ cat ksh.test2 ] && print FUBAR! || print OK! $ $ /bin/ksh93 ksh.test2 OK! $ /bin/ksh93 -x ksh.test2 + ] + print FUBAR! FUBAR! $ Trying to find out why this is... (8 Replies)
Discussion started by: lthorson
8 Replies

5. UNIX for Advanced & Expert Users

Install ksh93 for cygwin

Hi, Does anyone know where can I get ksh93 for installation on CYGWIN. Thanks? (1 Reply)
Discussion started by: devtakh
1 Replies

6. Shell Programming and Scripting

Performance degradation with KSH93

Hi, I have a script that calls an external program to perform some calculations and then I read with "grep" and "sed" values from the output files. I've noticed that performance of KSH93 degrades with every iteration. The output files are all the same size, so I don't understand why after the... (2 Replies)
Discussion started by: i.f.schulz
2 Replies

7. Shell Programming and Scripting

ksh88 or ksh93

Hi all! Does anybody know how can I check if any UNIX installation has implemented ksh88 or ksh93? Thanks in advance. NÚstor. (3 Replies)
Discussion started by: Nestor
3 Replies

8. Shell Programming and Scripting

Remove a byte(Last byte from the last line)

Hi All Can anyone please suggest me how to remove the last byte from a falt file .This is from the last line's last BYTE. Please suggest me something. Thank's and regards Vinay (1 Reply)
Discussion started by: vinayrao
1 Replies

9. Shell Programming and Scripting

Check if 2 files are identical byte-to-byte?

In my server migration requirement, I need to compare if one file on old server is exactly the same as the corresponding file on the new server. For diff and comm, the inputs need to be sorted. But I do not want to disturb the content of the file and need to find byte-to-byte match. Please... (4 Replies)
Discussion started by: krishmaths
4 Replies

10. Shell Programming and Scripting

ksh93 deprecation...

Any means of running ksh93 in a ksh88-mode? Might sound odd, but I want/need to restrict U/Win-developed scripts to correspond to the ksh88 version on my Solaris environment(s). Thanks. (2 Replies)
Discussion started by: curleb
2 Replies

Featured Tech Videos