ksh

How to convert the string to negative decimal number in ksh - unix

≯℡__Kan透↙ 提交于 2019-12-12 03:43:29
问题 if a particular character is found at certain position, I need to replace it with a number and make entire string as negative decimal number . for ex: if } is found at 14th position it need to be replaced with 2 and make it negative decimal number: sed -e 's/^\(.\{9\}\)}/.\12/;s/\(.\)/-\1/' <<< '123 00}000150}' output is: -.123 00}0001502 But, expected output is: 123 -00}00015.02 回答1: This will work: sed -e 's/\(.* \)\(.\{8\}\)\(.*\)}/\1-\2.\32/' <<< '123 00}000150}' \1 will have value: 123 (

How to split input string into multiple variable

风流意气都作罢 提交于 2019-12-12 03:16:47
问题 I'm working on shell script and trying to split user input into multiple variable and use them at different places. User input is not fixed so can't really assign fixed number of variable, input is separated by comma , ./user_input.ksh -string /m01,/m02,/m03 #!/bin/ksh STR=$2 function showMounts { echo "$STR" arr=($(tr ',' ' ' <<< "$STR")) printf "%s\n" "$(arr[@]}" for x in "$(arr[@]}" do free_space=`df -h "$x" | grep -v "Avail" | awk '{print $4}'` echo "$x": free_space "$free_space" done

Use ksh to parse a name and a date from a line and remove the line if the date is older than 50 days

你。 提交于 2019-12-12 03:04:05
问题 I have a test file with the following format, It contains the username_date when the user was locked from the database. $ cat lockedusers.txt TEST1_21062016 TEST2_02122015 TEST3_01032016 TEST4_01042016 $ I'm writing a ksh script and faced with this difficult scenario for my level of scripting. What I would like to do is: Read the line from text file, If the date value of this line is older than 50 days, then read the line till before the underscore character e.g. TEST1 into a variable, and

How to delete all lines except lines that include TRUNCATE - INSERT, incluiding PACK name

偶尔善良 提交于 2019-12-12 02:01:24
问题 this is an extension to this question: How to delete all lines except lines that include TRUNCATE - INSERT I had earlier asked that question because i needed some help deleting line from a generated script, thanx from some great help from anubhava i was able to solve the problem, but now the proble is that i have been asked to include the pack name into my generated script, so: PROCEDURE VALIDA_CAMBIO_GPR TRUNCATE TMP_MOD_PVA INSERT TMP_MOD_PVA PROCEDURE AJUSTAR_FECHAS INSERT PRO_TDA_VARLOG

bash - The Best Elegant way to disable log file

最后都变了- 提交于 2019-12-11 22:26:57
问题 dear friends and colleges the following code , is the basic concept of my log file in my bash script this Code help me to understand each step in my bash script or in case we need to make troubleshooting but some times I want to disable the Log creation because we not need the log and want to make the script more efficiency ( call to Log function each line in the script take time and make the script more heavy ) so my question my friends: What the best elegant way to disable the log file?

Single/double quotes ksh

[亡魂溺海] 提交于 2019-12-11 19:55:15
问题 When I set my PS1='$PWD' the command line shows me the path to the current directory: /home/myname and it changes when I change the directory. But when I change it to "$PWD" ( double quotes ) it always shows me the /home/myname no matter where I am at the moment. From what I've read it says that single quotes prints exactly what it is in it and don't expand special symbols like $. So why is it working that way? 回答1: The "$PWD" resolves immediately. So you're essentially setting PS1 to a fixed

whats is the meaning of using exec and then read in ksh script

。_饼干妹妹 提交于 2019-12-11 19:48:29
问题 THe script is like exec 8< $SEQ_FILE read -u8 DATE SEQ_NUMBER Can you please help me in understanding what this means? 回答1: The exec 8< $SEQ_FILE opens the file $SEQ_FILE for reading and associates it with file descriptor 8 . All further commands can then read from that file descriptor. The command read -u8 DATE SEQ_NUMBER then does exactly that. It reads one line from that file and puts the line into two variables (split according to shell rules, typically at a space). 来源: https:/

Transpose Columns in a single comma separated row conditionally

好久不见. 提交于 2019-12-11 18:59:57
问题 I have an input file that looks like this: aaa 111 aaa 222 aaa 333 bbb 444 bbb 555 I want to create a transposed output file that looks like this: aaa 111,222,333 bbb 444,555 How can I do this using awk , sed , etc? 回答1: One way using awk : $ awk '{a[$1]=a[$1]?a[$1]","$2:$2}END{for(k in a)print k,a[k]}' file aaa 111,222,333 bbb 444,555 And if your implementation of awk doesn't support the ternary operator then: $ awk 'a[$1]{a[$1]=a[$1]","$2;next}{a[$1]=$2}END{for(k in a)print k,a[k]}' file

Pass hash-sign-starting-string parameter to a shell script

旧时模样 提交于 2019-12-11 16:27:50
问题 I try to pass a string containted between two # sign to a ksh script : Will #> ./a.ksh #This is a string# Will #> Nothing is prompted, the execpeted output would be : Will #> ./a.ksh #This is a string# #This is a string# Below the a.ksh script. a.ksh echo $1 echo "$1" echo ${1} echo "${1}" I have tried to protect my $1 variable by any means I knew but I can't get anything starting with # to be displayed. Those following don't work : #> ./a.ksh #Hello #> ./a.ksh # But this do : #> ./a.ksh

ksh script spawns unwanted child with the same name

不问归期 提交于 2019-12-11 15:49:21
问题 So.. I use KSH on Solaris8 for quite long but this is the first time I got something like this: I start a script - let's call it splitCfg. When I call pgrep -x splitCfg I'm finding two instances of this script - the main instance and a child of my script (output from ps): root 28069 25107 0 20:22:01 pts/10 0:00 splitCfg root 4668 28069 0 20:22:50 pts/10 0:00 splitCfg As you can see - the first instance is a parent for a child. However - there is no subprocess created from the main script.