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

1
vote
2answers
257 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
933 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
265 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
57 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
4k 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
529 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 ...
4
votes
3answers
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
132 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
256 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
359 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
6k 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. ...
4
votes
1answer
64 views

Extract data from two files

I have two files as given below Output1.csv 201319107648361,12:27:04,12:27:14,0:0:10 secs 201319109089878,12:27:04,12:27:15,0:0:11 secs 201319108968961,12:27:15,12:27:54,0:0:9 secs ...
4
votes
1answer
180 views

returncode of command in a pipline [duplicate]

The following script runs on Solaris using /bin/ksh and on Linux using /bin/sh cmd | tee -a cmd.log | tail exit $? The output of cmd is saved in a file cmd.log and the last lines are displayed on ...
10
votes
5answers
18k views

Delete First line of a file

How can I delete the first line of a file and keep the changes? I tried this but it erases the whole content of the file. $sed 1d file.txt > file.txt
4
votes
4answers
3k views

Convert Unix timestamp into human-readable format on AIX

I need to convert unix timestamp (number of seconds since 1970, e.g. 1381260225 is Tue Oct 8 19:23:45 GMT 2013) into a standard human-readable format. I could get some answers by googling but those ...
2
votes
2answers
112 views

Awk not rendering any result

My goal is to get the file created in the current month in a directory. It seems that the command is correct but not rendering any result: Date=`date '+%b'` echo $Date Oct ls -l | awk -v d="$Date" ...
2
votes
5answers
2k views

Sum the values in a column except the header

I have a file as given below -------------------------------------------------------------- Name_Customer Item_Purchased Item_Amount Credit ...
1
vote
4answers
320 views

Reusing a variable

I was breaking my head for a day still not successful. I have this script: #!/bin/ksh fname=$1 for batchname in $(grep -i "Processing batch" $fname | cut -d "'" -f2) do Batch_state=`grep -c -i ...
2
votes
1answer
554 views

ksh:Get files created on specific date in directory [duplicate]

I want get the files that were created on specific date in a directory > ll total 36 -rw-rw-r-- 1 tak tak 212 Oct 08 07:06 name.log -rw-rw-r-- 1 tak tak 494 ...
1
vote
2answers
101 views

AWK special character

If i want to awk the below pattern in a file Mobilenumber '91_987986787688899' was successful I used the below code awk '/Mobilenumber '91_987986787688899' was successful/ {print $0}' Log Filename ...
1
vote
1answer
82 views

ksh: to print the fourth line above the matched line and second line after the matched line

This is the sample log file : 64.242.88.10 - - [07/Mar/2004:16:05:49 -0800] "GET /twiki/bin/edit/Main/Double_bounce_sender?topicparent=Main.ConfigurationVariables HTTP/1.1" 401 12846 64.242.88.10 - - ...
0
votes
2answers
2k views

ksh :To store the output of a awk command in an array

I've the following awk command: awk -F ' ' '{ print $NF }' log filename And it gives the output as below: 06:00:00 parameters: SDS (2) no no no no doc=4000000000). information: 0 5898 5898 ...
3
votes
3answers
4k views

Subtracting dates in unix

Is there a way in unix to subtract a month or at least 30 days from a specific date? The date is to be inputted by the user. Example: 2012-11-19 - 1 month = 2013-10-19 This one doesn't work: date ...
2
votes
1answer
225 views

Get the last executed command line in ksh

Is there a way to get the last executed command possibly together with the arguments within a ksh script? I am using mksh with cygwin. I tried fc -nl -1, but the script throws a "“fc: history ...
2
votes
2answers
3k views

Exporting a variable with dot (.) in it

How to export a variable which has dot in it. I get 'invalid variable name' when I tried : export my.home=/tmp/someDir -ksh: my.home=/tmp/someDir: invalid variable name Even escaping metacharacter ...
3
votes
2answers
210 views

Getting the complete command line that caused an ERR , while trap

How do I make trap to return the command that caused an ERR? $function err_handler() { echo "$0 caused the error"; } $ trap err_handler ERR $ grep -ci "failed" test4 &>/dev/null -bash caused ...
1
vote
1answer
659 views

Error out shell script if plsql program fails

In the shell script, I am calling a PLSQL stored procedure sqlplus -s <<EOF $v_fcp_login set head off feed off serverout on size 1000000 exec ...
4
votes
1answer
588 views

Scoping variables in ksh

In ksh, I have two variables with the same name , one global , other one is local to a function #!/bin/ksh LOG_FILE=lf function exec_script { local LOG_FILE=f print $LOG_FILE } exec_script ...
7
votes
2answers
554 views

What does this ${@:2} mean in shell scripting

I see this in a shell script. variable=${@:2} What is it doing?
1
vote
2answers
5k views

How can i run a part of a script as a different user?

#!/bin/ksh (some code) Log=~/my.log chown USER1 filename su - USER1 -c " date | tee -a ${Log} 2>&1; cd /blah/blah if [ SOMECONDITION ] then sh ./somescript.ksh > logfile fi exit" | tee -a ...
1
vote
2answers
1k views

How to print dates between two different dates [duplicate]

I want to print dates between 2 different dates (i.e. start date and two dates) If start date is 2013-09-05 and end date is 2013-09-10, then I want result as 2013-09-05 2013-09-06 2013-09-07 ...
1
vote
1answer
154 views

Variable name completion in ksh

While I am in bash , I am able to do a tab complete with environment variable names, but with ksh I am not able to do so. How can I get it done with KSH? I am using mksh with cygwin.
0
votes
3answers
535 views

Need to create a ksh script for transferring files between application server and db server

I have a requirement where I need to automate the transfer of a particular file from one location in the application server to the database server. I can do it manually by using these steps but I ...
0
votes
1answer
38 views

Output redirect complexities

I'm trying to have a script exit with an error in the event it can't reach an X server: xset -q &> /dev/null || { echo "The Display Server is BROKEN. Aborting."; exit 1; } However, I'm getting ...
1
vote
1answer
154 views

why csv is consuming more file size in my unix script?

I'm using this unix script which it is fetching records in the form of csv. I have a SQL query used for this purpose. It contains below information SET PAGESIZE 5000 SET COLSEP "," SET LINESIZE 2000 ...
2
votes
2answers
101 views

open a file and copy the listed files to another folder

I have a file named file1.txtcontaining file names like below : filea.txt fileb.txt filec.txt I want to copy the files listed in file1.txt to another folder. What is the UNIX command to use? (the ...
1
vote
3answers
117 views

How to print to the left and right of already printed output

I have a command say printf "%5s1" and its output is: 1 How can I print digit 2 to left and digit 3 to right of already printed 1. So, the output looks like below: 213 So, there is one ...
3
votes
2answers
925 views

Overwriting line in unix shell after printing

How can I modify a line after printing it in unix shell.We can delete the line and write again by using \r as shown below,but how can I overwrite on existing line and not delete it completely and get ...
3
votes
2answers
329 views

Writing scripts that use different commands in different shells [duplicate]

How can I write a script that is shell independent? I want to be able to run one script which will run in ksh, sh and bash. For example: If I have a line in my script like whence ls which will run in ...
2
votes
3answers
415 views

Unexpected condition outcome in a ksh script

I'm new to shell scripting. The below code is not working. Can anyone help me on this? I've given explanation for all the lines: #!/bin/ksh cat example.txt | while read LINE # ...
0
votes
1answer
108 views

How to only output [a-z;A-Z;0-9;|] chars with ksh?

How can I "whitelist"/output only the (ENglish) a-z;A-Z;0-9;| chars and space in ksh/OpenBSD 5.3? $ echo 'ASDF"`date`ew � kd A | A' ASDF"`date`ew � kd A | A $ echo 'ASDF"`date`ew � kd A | A' | MAGIC ...
1
vote
1answer
203 views

How to give variable to a KSH script with a CGI?

index.sh is in the cgi-bin directory: #!/usr/bin/ksh echo 'Content-type: text/html <html><body> <form action=FOO.KSH method=POST> <input type=submit value=fgrep ...
1
vote
2answers
516 views

how to escape unusual/uniq characters from expect scripts?

in expect script I can set any command or character to run it on remote machine but the sad thing is that expect cant send the same character as they defined in the expect script for example I want ...
2
votes
1answer
268 views

how to replace IP address on remote host using expect

I wrote the following expect script in order to replace the IP address on remote Linux machine I use a perl one-liner for this task I get errors about can't read "HOME": no such variable , Please ...
4
votes
3answers
4k views

Can ksh on AIX be configured to use the tab key for filename completion?

I have some AIX 7 servers that are restricted to what software I can install and wonder if I can get ksh to use the tab key to complete filenames at the shell promot. The man pages are sparse for ksh ...
1
vote
1answer
327 views

How do you track memory usage in a ksh93 script

We have a number of ksh scripts that run forever (inside a while loop), or at least until a shutdown event is delivered to them. We had a project where these scripts where converted to ksh93 (and ...
2
votes
3answers
1k views

Need to trim the names of file names

I have files in UNIX directory which have a unique number starting with, i have to remove the unique id followed by '-' from the file name and need to have regular file. Any help is appreciated. ...
2
votes
1answer
401 views

xterm resizing causes shell to mess up

I'm using reflection x, which uses xterm as the terminal emulator. If I maximize and minimize the window several times, when I try to access previous commands, the text becomes messed up. The issue ...