Operating System - HP-UX
1832111 Members
3001 Online
110038 Solutions
New Discussion

shell string manipulation

 
Ricardo_78
Occasional Contributor

shell string manipulation

Hi, does anyone know how to make this work in hp-ux:

#!/bin/sh
.
.
.
line=...
data=${line:0:10}

i'm getting this error:
./script: data=${line:0:10}: bad substitution

but in linux works... does anyone knows an equivalent to hp-ux?
7 REPLIES 7
Alan Meyer_4
Respected Contributor

Re: shell string manipulation

data=`echo $line |cut -c1-10`
" I may not be certified, but I am certifiable... "
RAC_1
Honored Contributor

Re: shell string manipulation

How does line look like and what you want to extract from it??
There is no substitute to HARDWORK
Mel Burslan
Honored Contributor

Re: shell string manipulation

data=`echo $line|cut -c1-10`
________________________________
UNIX because I majored in cryptology...
Alan Meyer_4
Respected Contributor

Re: shell string manipulation

sorry
data=`echo $line |cut -c1-11`
" I may not be certified, but I am certifiable... "
Marvin Strong
Honored Contributor

Re: shell string manipulation

if you prefer an awk solution.

echo $line | awk '{print substr($0,0,10)}'

curt larson_1
Honored Contributor

Re: shell string manipulation

parameter substitution with an offset isn't implemented in hp-ux's usual shells, /usr/bin/sh and /usr/bin/ksh. This has been implemented starting with ksh93 (so much for a modern programming environment). this syntax maybe implemented in the dtksh shell, /usr/dt/bin/dtksh. otherwise you'll just have to use a shell that does implement it.

but one way to get the first 10 characters would be to do something like this:

typeset -L10 tmp10

tmp10=$line
data=$tmp10
Sandman!
Honored Contributor

Re: shell string manipulation

What's stored in line and what string manipulation are you trying on data? Appending a string or extracting a substring from it or other?? Please elaborate on what you are trying to get at.

regards!