Tagged Questions

The Korn shell (ksh) is a shell with advanced scripting features, commonly found on commercial unices and some BSD systems but rarely used on Linux.

learn more… | top users | synonyms

2
votes
2answers
56 views

Replacing a pattern with another between first and second occurrence of a pattern in file

Want the comma's (,) replaced by the alphabet u between the first occurrence of y till the second occurrence of y. Given below is the sample input file. 100y00893225900,008932259,06,2013,NOKIA Q ...
0
votes
2answers
369 views

perl one liners + match word and delete string after separator

I work with linux/solaris machines and I need to add some rule in my ksh script: Please advise how to match the password word in file, and delete the value password after the separator "=" with perl ...
0
votes
1answer
350 views

perl one liners + print line if match last word but with space

The following perl syntax will print the line in case line was ended with "DUPLEX" But Sometimes DUPLEX have one space or more as "DUPLEX " so in this case line will not printed Please ...
1
vote
2answers
52 views

Is this an array?

I'm currently looking at an existing script that have something like this: variable='val1 val2 val3 val4' Is this another way of setting an array? If not, what is it?
1
vote
1answer
91 views

Count number of elements in an array

I would like to ask if there is a way to count the number of elements in an array in ksh.
1
vote
2answers
113 views

Keeping the latest two version and delete the remaining

I have a list of files (say xsl format below) in one directory. I want to keep the last two version of all files. (I can delete the remaing files) {A}_1.0.xsl {A}_2.0.xsl {A}_3.0.xsl {A}_4.1.xsl ...
1
vote
2answers
62 views

Is there an equivalent to bash's “nocaseglob” in ksh?

I would like to do what is mentioned in How to match case insensitive patterns with ls? except for ksh. Is it possible to do it without any pain(regex)?
1
vote
1answer
32 views

Problematic quotations

#!/bin/ksh typeset FILE_SIZE1=$(stat -f '%z' test.txt); typeset -r BK_STATARGS="-f '%z'" typeset FILE_SIZE2=$(stat ${BK_STATARGS} test.txt); echo without arg var ${FILE_SIZE1} echo with arg var... ...
2
votes
2answers
104 views

Help with 64-bit integers in scripts?

Maybe I'm overthinking this (although I don't think I am)....or maybe there's a neater way of solving my problem ? I have a requirement that if a file is larger than 1GB, it gets split into smaller ...
0
votes
1answer
116 views

Truncating strings after a word in unix [closed]

I have a sentence Albert Einstein was born in Ulm, in the Kingdom of Württemberg in the German Empire on 14 March 1879. I want to truncate the above sentence after kingdom and look like the ...
1
vote
1answer
89 views

Crontab Triple Redirect

I have a very basic understanding of redirects, but I have come across a cronjob with redirects which I do not understand. 00 19 * * 1-5 /apps/app/scripts/doit.sh a np cron > ...
4
votes
3answers
299 views

Sort all directories based on their size

I'd like to sort all the directories/files in a specific directory based on their size (using du -sh "name"). I need to apply this command to all directories in my location, then sort them based on ...
1
vote
3answers
177 views

Quoting in command substitution

The command pdftk FileOne.pdf "File two.pdf" output Combined.pdf works as expected, merging PDF's One and Two. However, if I put the filenames in a file FileOne.pdf "File Two.pdf" and ...
2
votes
3answers
145 views

Display what has been copied by `cp` (using `ksh`)

I'd like to get output showing what has been copied by cp. The only problem is how to do it when I cp many files at a time. For instance, cp ./sourceDir/* $destinationPath/.
0
votes
1answer
101 views

What does Grep */* mean in KSH

In ksh, what does grep */*[myPattern] mean?
2
votes
2answers
103 views

Replicate a directory and file names n times

I have folder which has some data (files) in that with the name 201311261418 And a file 201311261418.eob In my scenario I need to replicate this folder and file names n times with the appended ...
0
votes
2answers
288 views

cp all files and subdirectories in a directory ksh

How can I do a cp to copy all files including all sub-directories in the current directory. I looked at the man page, but I can't figure out how to do it.
2
votes
3answers
80 views

Change value of a strings representing number

I have the following expression : a="2013" How can I change the value of a to "2012".
1
vote
1answer
338 views

Grep pattern in ksh [duplicate]

a small question regarding grep. I'm doing : find . -type d And I have three directories : ./backup-2013-11-27 ./backup-2013-11-26 ./backup-2013-11-28 If I only want to retrieve the one from ...
0
votes
1answer
52 views

Test what cd has done ksh

I'm facing a small issue here. I'm doing : cd $(find . -type d | grep "${4:0:4}.*${4:4:2}.*${4:6:2}") $4 is a data entered from the user. However, if the user doesn't respect the format to enter, ...
0
votes
1answer
295 views

ksh if with several conditions

I'd like to know what's the syntax for this kind of if in ksh : if [[ $tmpEngine != "a" || $tmpEngine != "b" || $tmpEngine != "s" ]]; then ... fi Actually, my code doesn't work, what's the ...
4
votes
2answers
9k views

Remove all files created before a certain date

I have a directory containing a high number of files (like logs for every day of the year). I would like to remove all files created before let's say 22/11. How can I achieve that ? Must I use find ...
0
votes
1answer
308 views

Sorting with command ls in unix (ksh) [closed]

I'm wondering how does the sort works with ls. For example: ls - lrt tri par date ls - lSr par size, ... However I don't see how this pattern works.
2
votes
1answer
555 views

KSH : cp only based on file size

I would like to write a small script copying from a directory A to directory B all the files with the .log extension. So in my directory A, I've : ls : a.log b.log c.log Here is the pseudo-code I ...
0
votes
0answers
96 views

String length limitation for user input

There is simple korn shell (bash has the same behavior) script: #!/bin/ksh read userInput I have two Solaris 9/10 servers. On one of the server i can type long string while read is running. But on ...
0
votes
1answer
44 views

KSH conventions scripting [closed]

I'm writing scripts in ksh atm. I'd like to know if there is any "conventions" as for example, always doing "unset" before using a variable, or using typeset to define a new variable, etc.
1
vote
1answer
471 views

Changing the current directory using a script (ksh)

I'm launching my script from echo $PWD ---> /x. I want my script to change my current directory. So my script contains +- this : cd /y exit 0 However, when my script ends, I'm stils in echo $PWD ...
0
votes
1answer
36 views

Using variable in KSH function

I tried to have a switch if either an option is set or not while getopts "s:u:d:e:ch" _OPTION; do case $_OPTION in ... c) isCSet="Y" then I'm ...
0
votes
1answer
616 views

Using alias in another script (ksh)

I'm writing a ksh script, and I'd like to use a command define by an alias in my .profile file, in my script. I tried this command in the folder containing my script, and it works. However, in my ...
0
votes
3answers
78 views

Ksh script warnings [closed]

While running my script, I got the following message (it's not an error strictly speaking, because the execution go ahead after) : myScript -s test -u test2 pk_copylogs[2]: hist: :: not found ...
0
votes
1answer
191 views

Function, return value using pwd in KSH

I tried to write a small ksh script: fDestExists (){ cd /tmp read vANSWER?" >> Do you want to create a repository in pwd ? Type YES or NO" echo " |----> $(fGetDatum) You ...
1
vote
1answer
86 views

How to retrieve environment variable from string name in KSH

I've the following variable : x="envVar" and 'envVar' is the one of my environment variable's name containing a path (of a folder by instance). So I'd like to do cd $x but it doesn't work. ...
1
vote
1answer
67 views

Looping through commands' results, KSH script

I'd like to put two strings in two different variables. Let's take a small example. after a simple grep, I got this : $ grep nl.*acc.*bas : ABAS01=... ABAS02=... I'd like to have two variables, ...
0
votes
1answer
106 views

How to make options mandatory in KSH script

Here is the skeleton to catch arguments in my script : # fMain(){ while getopts "d:e:h" _OPTION; do case $_OPTION in d) ...
2
votes
1answer
193 views

How to have a bash script perform a specific action on errors of _each_ command?

Similarly to set -e performs an exit on "uncaught" $? != 0, I'd like to have this event trigger the execution of another command, e.g. a logger call. How can this be done?
8
votes
2answers
364 views

Merge three file in to a single master file by excluding the header in 2nd and 3rd files

I have three file with n number of lines as given below sample1.txt ------------------------------ Date Time Name ------------------------------ 2013/10/12 12:09:09 Krish ...
4
votes
1answer
66 views

ksh variable substitution format?

I have variables named var1EMI, var2EMI, var1DDE, var2DDE, etc and I need to be able to iterate over them like this; for dir in var1 var2 do echo "EMI value for " $dir " is " ${${dir}EMI} echo ...
1
vote
2answers
226 views

viewing variable values in a KSH script

I am using a KSH script that creates numerous variables from fairly complex code. What command can I place in the script to view the value of these variables as they are created? Would ECHO be the ...
4
votes
3answers
669 views

using awk to split a line on single spaces not multiples

I'm trying to split a line that I have no control over the format of. If parameter 7 and 8 are missing which is possible they will be replaced by a space so I would end up with, field1 field2 field3 ...
0
votes
2answers
214 views

Checking if one of 4 variables starts with string &red in ksh

I'm trying to check if one of 4 variables starts with the string "&red" and I'm struggling to get the match to work. At the moment I've got this, if [[ $filemsgCICS = "&red"* || ...
1
vote
2answers
56 views

copy a section of data from stdin [closed]

I am running a script that takes its input from stdin. This input can end up being very large so I want to extract the part I'm interested in to a temp file. The first line contains "[cics]" and I ...
0
votes
3answers
2k views

Convert Month Number to Month Name

is there a way to convert month number to name? example: 2013-10-22 will become Oct 22 I don't have the GNU date and my OS is AIX.
4
votes
5answers
3k views

Next day of the user entered date - date +1 day

I am new to scripting I needed a script in the AIX environment to get the next days date based on the date entered by the user of the script. After hard time browsing for this I got a piece of code ...
1
vote
1answer
456 views

0403-053 Expression is not complete; more tokens expected

I have this piece of code given below as a part of my main script if [ -e /tmp/rsm/Logs/filename_$$.txt ]; then { total=0 for files in $(<filename_$$.txt); do #cd /tmp/rsm/Logs docs=`grep -i ...
3
votes
2answers
2k views

Need to get the difference between two time in seconds

The following two variables contain the start time and the end time , need to get the difference between these two time in seconds start_time=06:07:25 end_time=07:02:08 Desired Output diff_time= ...
0
votes
2answers
120 views

Shell script to find what package provides a file on OpenBSD

# for i in `pkg_info -q`; do pkg_info -L "$i" | grep ^/ | sed "s/^/$i/g" | perl -pe 's/\//\t\//'; done | grep tasklist.desktop xfce4-panel-4.10.0p2 ...
2
votes
1answer
211 views

tar and if-statement

I have a script that check if a file exist inside a tar file but something's wrong because it always go to the else part of the script. I am pretty sure that it shouldn't be that way. The date is in ...
0
votes
1answer
285 views

Extract a single file from a tar file and put it to another directory [duplicate]

I need to extract a single file from a tar file to another directory. So far I have this: This one extracts a single file to same directory: tar -xvf filename.tar ./file.txt I tried this but it's ...
0
votes
0answers
26 views

Variable Substitution in sed [duplicate]

I have this script and I need to count the lines inside a file, then pass the number of lines counted to a for loop so that I can get the contents of each line and put it in a variable. My question ...
2
votes
3answers
5k views

Multiple pattern match and print in single line

I need to match two patterns in a log file and need to get the next line of the one of the pattern (out of two patterns) that is matched, finally need to print these three values in a single line. ...