Substring AIX ksh


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Substring AIX ksh
# 1  
Old 09-08-2014
Substring AIX ksh

I am trying to obtain a substring in AIX, but unable to obtain result

Code:
${var:1:3}
ksh: ${var:1:3}: bad substitution

# 2  
Old 09-08-2014
The substring expansions are not available in the 1988 version of ksh. Does your system include a command called ksh93?
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 09-08-2014
POSIX sh doesn't support that notation but often you can emulate it with short string using something like this:

Code:
$ v=substring
$ echo ${v:1:3}
sh: 2: Bad substitution
$ echo ${v%${v#???}}
sub

This User Gave Thanks to neutronscott For This Post:
# 4  
Old 09-08-2014
Quote:
Originally Posted by tostay2003
I am trying to obtain a substring in AIX
What you tried is ksh93 only, as Don Cragun already said. The default shell (/usr/bin/ksh and /usr/bin/sh, which is a link to the former) in AIX is a ksh88. A ksh93 (revision t in AIX 7.1, TL3) is only available as /usr/bin/ksh93.

To sum it up, Don was spot on with his suspicion.

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

AIX - bc and ksh

from command line in AIX: bc 18+14 32 and ctrl D to exit. i want to write shell script: !#/bin/ksh startdate=18 enddate=14 cd /tmp bc $startdate + $enddate my goal is to tell me end date is 14 days from today. With 58 posts, you have been a member long enough to use good... (2 Replies)
Discussion started by: lawsongeek
2 Replies

2. Shell Programming and Scripting

How to compare day in ksh on AIX?

we made a script in which i am putting a day in a variable by this command d8 = `date +%a` after that I am checking for next working day meand week days only for eg. if today is Monday than previous day would be Friday and if today is Friday than next day is Monday else it would be date +1... (1 Reply)
Discussion started by: pallvi_mahajan
1 Replies

3. Shell Programming and Scripting

AIX 5.3 ksh Scripting

Hi, I posted a request for sever OS types earlier, but got no response. In an attempt to at least have a starting point, I think scaling it to one OS is preferred. Once I see the gist of it I can modify to account for different cases. I need a script that will go and check to see if an LDAP... (2 Replies)
Discussion started by: tekster2
2 Replies

4. Shell Programming and Scripting

KSH: A PROBLEM awk SUBSTRING

Hi Gurus, I am working with a korn shell script to simplify some operations of creation file of spool for a Bulk-Copy. Thi is my code: In a for cycle: gzcat ${file} |awk '{ print substr($0,1,5)";"substr($0,108,122)";"substr($0,124,131)";"substr($0,139,152)";"substr($0,154,163)";"}' >>... (6 Replies)
Discussion started by: GERMANICO
6 Replies

5. Shell Programming and Scripting

help in ksh scripting in aix

Hello gurus I am looking for a script : We need to generate a file list created by user id on a AIX box. Criteria 1: other than userid : dwimpid & aiadmin Criteria 2: Files older than 2 months ( it can be any user id ). File Path to Look: /project and /project1 Thx silu (7 Replies)
Discussion started by: silu
7 Replies

6. Shell Programming and Scripting

Need help in writing AIX ksh scripting

I need to write the script for the below constraints. Need your help urgently The PATH environment variable must conform to the following: • World-writeable directories (/tmp, /var/tmp etc) must not be placed in the PATH variable. • System directories must always be placed before local... (1 Reply)
Discussion started by: kmvinay
1 Replies

7. Shell Programming and Scripting

Help with ksh scripting in AIX

I am looking for a script which does the following Script will run daily. 1.It will get snapshot off all filesystems including nfs mounts, automounts and clearcase mounts. 2.Then it will compare new snapshot with the snapshot created in the previous run. 3.If filesystem exists in... (20 Replies)
Discussion started by: saidiya
20 Replies

8. AIX

AIX Replace a substring

Hi, I have a very simple problem but I am new to scripting and I cannot find a way around it. I am using KSH. I have a date say 001200AM But i want to replace the first 00 to 12 so that the format will now be: 121200AM Can anyone help me? (2 Replies)
Discussion started by: 3vilwyatt
2 Replies

9. AIX

help needed on aix ksh

i am trying to convert .ksh script to .bat in windows box , it says awk is not recognized as internal or external command. this is the sample .ksh script , even if i change awk to gawk it does not work its giving me syntax error, at line one ---- it's pointing ":" and "fund:" some one plzz help.... (0 Replies)
Discussion started by: 2.5lt V8
0 Replies

10. UNIX for Dummies Questions & Answers

ksh substring commands

I am trying to get various portions of strings in my script, but am getting a substitution error. I followed the syntax that was described when I goggled this, but I can't get anything to work. #! /bin/ksh/ hello="adklafk;afak" #hello=${hello:3} hello=${$hello:3} happy="hey" echo... (1 Reply)
Discussion started by: anderssl
1 Replies
Login or Register to Ask a Question