The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Back-to-Back Connection using HBAs aldowsary IP Networking 3 11-28-2008 10:21 PM
back to back printing in UNIX amirthraj_12 AIX 3 05-06-2008 08:42 AM
ksh93 deprecation... curleb Shell Programming and Scripting 2 03-17-2008 08:36 PM
Strange array handling in ksh93 bakunin Shell Programming and Scripting 3 10-24-2005 01:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-25-2006
The Doctor The Doctor is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 11
Using subsring in ksh93 - How to stuff a byte back in


Code:
#!/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
  then
     ${I:27:1}="-"           # change byte 27 to a dash "-"   <-- ### WARNING, this syntax is invalid ###          
  else
    :                        # no change to byte 27 
  fi  
  print "$I"                 # write out record  
done

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 12:31 AM.. Reason: changed commas to colons in ${I:27:1}
  #2 (permalink)  
Old 03-25-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
You seem to have some mutant form of ksh93. That syntax is not legal. You should be using colons, not commas...
Code:
$ x=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLNMOPQRSTUVWXYZ
$ echo $x
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLNMOPQRSTUVWXYZ
$ echo ${x,27,1}
/opt/ksh93/bin/ksh: syntax error: `,' unexpected
$ echo ${x:27:1}
B
$ 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....

Code:
$ x=${x:0:27}'-'${x:28}
$ echo $x
abcdefghijklmnopqrstuvwxyzA-CDEFGHIJKLNMOPQRSTUVWXYZ
$

  #3 (permalink)  
Old 03-26-2006
The Doctor The Doctor is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 11
Quote:
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 -->
Quote:
x=${x:0:27}'-'${x:28}
is simple & very straightforward. Just what I was looking for. Thx again.

Last edited by The Doctor; 03-26-2006 at 12:41 AM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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




All times are GMT -4. The time now is 08:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0