ksh

How can I extract a substring after a certain string in ksh?

和自甴很熟 提交于 2019-12-25 13:46:11
问题 If I have a string like this: The important variable=123 the rest is not important. I want to extract the "123" part in ksh. So far I have tried: print awk ' {substr($line, 20) }' | read TEMP_VALUE (This 20 part is just temporary, until I work out how to extract the start position of a string.) But this just prints awk ' {substr($line, 20) }' | read TEMP_VALUE (though this format does work with code like this: print ${line} | awk '{print $1}' | read SINGLE_FILE ). Am I missing a simple

What would be the right way to declare an array within a script that will be called by cron?

自闭症网瘾萝莉.ら 提交于 2019-12-25 12:05:52
问题 I have written a KornShell (ksh) script that sets an array the following way: set -A fruits Apple Orange Banana Strawberry but when I am trying to run it from within cron, it raises the following error: Your "cron" job on myhost /myScript.sh produced the following output: myScript.sh: -A: bad option(s) I have tried many crontab syntax variants, such as: Attempt 1: 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /path/to/script/myScript.sh Attempt 2: 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /path

What would be the right way to declare an array within a script that will be called by cron?

╄→гoц情女王★ 提交于 2019-12-25 12:05:51
问题 I have written a KornShell (ksh) script that sets an array the following way: set -A fruits Apple Orange Banana Strawberry but when I am trying to run it from within cron, it raises the following error: Your "cron" job on myhost /myScript.sh produced the following output: myScript.sh: -A: bad option(s) I have tried many crontab syntax variants, such as: Attempt 1: 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /path/to/script/myScript.sh Attempt 2: 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /path

File redirection inside for loop

不问归期 提交于 2019-12-25 09:17:15
问题 I have am redirecting the file inside file but at the last the file is going to nullify, my code is like below #!/bin/ksh newlycreated=`cat /axphome/gdevarad/file.txt|awk '{print $1}'` for i in $newlycreated do cat file1.txt |grep -v $i > /axphome/gdevarad/file1.txt done file.txt contains india 30 pakistan 40 file1.txt contains india 30 pakistan 40 germany 50 japan 60 aus 70 回答1: Replace > /axphome/gdevarad/file1.txt with >> /axphome/gdevarad/file1.txt so you do not overwrite your results in

Put select result in a ksh variable

折月煮酒 提交于 2019-12-25 07:58:08
问题 using sql loader, I know I can reference a ksh variable in my ctl file. For example I can write LOAD DATA INFILE '$PATH_IN_KSH/my_file.dat' ... I would like to add a WHEN clause like this WHEN (125:125) = '$P_NUMBER' P_NUMBER would have the value of a column in a table that I would retrieve with a select query. Is it possible to do that ? retrieve a value from a column with a select and somehow put it in the ksh variable so the ctl file can see it. (something with sql plus?) Thank you 回答1: As

Put select result in a ksh variable

允我心安 提交于 2019-12-25 07:57:12
问题 using sql loader, I know I can reference a ksh variable in my ctl file. For example I can write LOAD DATA INFILE '$PATH_IN_KSH/my_file.dat' ... I would like to add a WHEN clause like this WHEN (125:125) = '$P_NUMBER' P_NUMBER would have the value of a column in a table that I would retrieve with a select query. Is it possible to do that ? retrieve a value from a column with a select and somehow put it in the ksh variable so the ctl file can see it. (something with sql plus?) Thank you 回答1: As

Echo: Argument List too long

喜欢而已 提交于 2019-12-25 07:39:57
问题 I'm running into an issue where my argument list for echo is too long and would like some ideas on how to get around this issue, or at least test for the condition so I can properly handle it, and it won't kill my script for file in `cat filelist`; do PROTOCOLS1=`egrep -i 'rsh|rsync|remsh' "$file" | egrep -v '^[ | ]*#'` FIELDS=`echo $PROTOCOLS1|wc -l` if [[ $FIELDS -gt 1024 ]]; then echo $file >> $debuglog else set -A myarray $PROTOCOLS1 do stuff..... fi done So the problem is that when my

i<=: Expression is not complete; more tokens expected. ksh

北战南征 提交于 2019-12-25 04:13:14
问题 i get this error: i<=: Expression is not complete; more tokens expected. This is the code: vr=`$line` set sep_mx=`echo $vr | awk '{ n=split($0,x,"@#;") print n }'` echo $sep_mx i=1 && while ((i<=$sep_mx)) do echo $vr | awk -v er=$i '{ n=split($0,x,"@#;") print x[er] }' ((i+=1)) done Anyone can help me? Thanks 回答1: To answer the original question, the error message already explains where the error occurs: In i<= in i<=: Expression is not complete; more tokens expected. is the result of the

syntax error issue while storing array value Unix Solaris Korn Shell

瘦欲@ 提交于 2019-12-25 02:49:37
问题 Here is my command in shell script. x=($(echo $x1 | cut -f3 -d" " | cut -f1 -d"]")) syntax error at line 818 : `(' unexpected If I remove this line its working Note: The same script runs in Linux OS when i try it in Solaris it throws error. 回答1: It depends on your ksh version: ksh93 $ ksh --version version sh (AT&T Research) 93u+ 2012-08-01 $ x1="one two three]four" $ x=($(echo $x1 | cut -f3 -d" " | cut -f1 -d"]")) $ echo ${x[0]} three ksh88 $ what /usr/bin/ksh /usr/bin/ksh: Version M-11/16

Pattern matching in ksh script

拟墨画扇 提交于 2019-12-25 01:35:45
问题 I have a URL parameters in a variable like a=44&search=My World here I want to do a pattern matching like if [ $a =~ "search" ] ; then value=1 else value=0 fi But it is not working in KSH script. 回答1: You need [[ for ksh regular expressions, not the Bourne shell [ . Although in this case it hardly seems worth using an RE. So: if [[ $a =~ "search" ]] then value=1 else value=0 fi 回答2: found=`echo $a | grep search` if [ -z $found ]; then value=0 else value=1 fi 来源: https://stackoverflow.com