Tag Info

New answers tagged

1

Check your quotes. In unix shells including bash: single quotes pass text unmodified to the program (so as you said passes ${PWW}, double quotes allow expansion of variables. In your example you want ${PWW} to be expanded but not $2, you can do this like this: awk "/${PWW}/"'{print $2}' awk /${PWW}/{print '$2'} awk "/${PWW}/{print \$2}"


2

Here is a pure-awk solution: $ awk 'FNR==NR{a[$1]=$2; next} {print a[$1]}' bar.txt foo.txt good bad okay large good bad How it works The script reads in bar.txt first and saves its information in array a. It then reads foo.txt and prints out the corresponding value. FNR==NR{a[$1]=$2; next} FNR is the number of lines read from the current file and NR ...


0

If I'm not mistaken, ksh88 does file name completion with Tab in vi command line editing mode if the viraw option is set.


1

It would be more efficient to rewrite this, thereby avoiding the issue in the first place: #!/bin/ksh get_file_totals() { if [ -e "$file_name" ] then cut -c4-7 "$file_name" else echo "error" # consider stderr by appending >&2 fi } file_name="$1" get_file_totals


2

You're invoking ksh. The kind of substitution you are wanting to do works only since ksh '93. Is there a chance you are using an older version? Run ksh and check for the existence of KSH_VERSION. If it doesn't exist or is before '93, it's too old.


1

Awk could do this easily if the output was in decimal, but it can't parse hexadecimal numbers (at least standard awk can't, some versions such as GNU awk can). You can use bc to do the conversion. This works on all POSIX systems. { echo "ibase=16"; cat input.txt; } | bc | awk 'NR==1 {origin = $0-1} $0!=origin+NR {print "Out-of-sequence number at line", ...


0

You can use sort with the option -c to check if the input data is sorted: -c Check that the single input file is ordered as specified by the arguments and the collating sequence of the current locale. Output shall not be sent to standard output. The exit code shall indicate whether or not disorder was detected or an error occurred. If ...


1

Here is one option: while read x; do echo $((16#$x)); done <yourfile | awk 's && $1!=s+1{exit(1)}{s=$1}' This shell command will produce an exit status of 1 (on fail) and 0 (on success). This command can be used e.g. in an if-clause like the following to produce the desired output: if while read x; do echo $((16#$x)); done < yourfile | awk ...


0

If you'd like strict sequence it can be easy done by produce etalon sequence and compare it with file [ $(comm --nocheck-order -3 \ <(sed '/\S/!d' file) \ <(printf "%X\n" \ $(seq $((16#$(sed '/./!d;q' file))) \ $((16#$(tac file|sed '/./!d;q')))))) ] && echo 'Numbers are not in sequence' || echo 'All numbers ...


0

If you are able to use find and if you are working on a "normal Unix filesystem" (that is, as defined in find(1) under -noleaf option description), then the following command can be used: find . -type d -links 2 Each directory has at least 2 names (hard links): . and its name. Its subdirectories, if any, will have a .. pointing to the parent directory, so ...


1

As others have remarked, you need to pass the get commands as input to sftp. You can do it with a here document. Also, note that sftp doesn't have a mget command. sftp "username@server:$path" <<'EOF' get ubpbilp* ./ get cust.cmp* ./ get bunc.cmp* ./ EOF SFTP isn't very convenient to script. If the server allows scp, use it. If you just want to copy ...


2

Perhaps like this: sftp username@server <<EOT cd $path get ubpbilp* get cust.cmp* get bunc.cmp* quit EOT as sftp doesn't support mget.


1

There are heuristics that can help you, but there is no fully reliable way. Otheus shows how to use file descriptors. That's a nice heuristic, which works in most cases. However there are edge cases where it fails, and there's no way to detect failures. Example: take the following script. #!/bin/sh set lsof -p$$ | sed 's/[0-9][0-9]*//' Make two copies ...


3

I'm going to make a first-stage stab at this. Someone else will hopefully improve. Before executing your script, the shell will open a file-descriptor to the file. Usually this is assigned at fd 255. At any rate, if there's an open fd, then lsof can find it. So we use lsof -p $$ and get the highest-file-descriptor's filename. lsof won't work with every ...


1

I have a workaround that seems to work. I created a separate ksh script that does all the db2 commands (establish a connection, then creates a table and grants permissions on it), and run that with any arguments needed. This means that it's running a set of commands in one su instance, despite using the -c part, so as to run it inside the script ...


2

awk provides pattern matching awk '/ELF*.executable/ { ... }' EDIT: in your case: find /opt -type f | xargs ls -let | awk 'BEGIN { OFS="\t" } /ELF*.executable/ { sprintf("file \"%s\"", $10) | getline type; print type,$1,$3,$4 }' | tr ":" "\t"


0

Use grep with option "-h" . -h, --no-filename Suppress the prefixing of file names on output. This is the default when there is only one file (or only standard input) to search. find ./files/ -name "*.txt" -print0 | xargs -0 grep -h "5|20150507"


1

grep command have -r option it searchs text recursive over directory example below: grep -r "5|20150507" ./ | awk -F ':' {'print $2'}


0

find ./files/ -name "*.txt" -print0 | xargs -0 grep "5|20150507" | awk 'BEGIN{FS=":"} {print $2}' You may have to play with the delimiter "FS=" as it could be a special character.


1

You can use piped I/O from a command in awk (at least gawk, I haven't tested this on Solaris): find . -type f | xargs ls -l | awk 'BEGIN { OFS="\t" } { command=sprintf("file \"%s\"", $9); command | getline type; close(command); print type, $3, $4 }' | tr ":" "\t" If your find supports it you can simplify this with find . -type f -ls | awk ... There's a ...


4

If your concern is about aliases, just do: [[ $(unalias -- "$cmd"; type -- "$cmd") = *builtin ]] ($(...) create a subshell environment, so unalias is only in effect there). If you're also concerned about functions, also run command unset -f -- "$cmd" before type.


0

I fear you maybe wasted your time implementing that; ksh93 supports the builtin command. E.g. with ksh version 93t 2008-11-04: $ builtin ...creates list of all builtins $ builtin jobs umask ...returns with exit code 0 $ builtin jobs time umask ...returns with exit code 1 and prints "builtin: time: not found" Note also that the builtin command is a ...


1

I like cuonglm's approach of probing the shell's capabilities to determine its version based on what is known to be different between versions. However, the check for $ERRNO could be fooled. While I was writing a script for ksh, I noticed that the -a option of ksh's built-in whence command appears to not be supported in older versions of ksh. This ...


0

Assuming your shell is Bash, you can do it like this: ssh user@hostname.com "cat -f /path/to/file"


2

If your OS supports FUSE, you can use SSHFS to mount a remote directory to a local one. Otherwise, assuming your shell is bash, you can still do it like this: program <(ssh b 'cat /path/to/file') But this only works if your program only wants to read from the file on machine b.


3

You should not be using exit inside your for loops - this causes the script to exit, and is why you're only getting one result. You should be using continue, which will stop the current loop from going on, but will go to the next element in the for loop. Swap both your exit statements to continue and you should find very different behavior, more in line ...


-1

CTRL+ALT+V or ESC CTRL+V Have typically proven very reliable as far as interactively determining the version of KSH you're using, however scripting them has proven more difficult.


3

I think that .sh.version has existed ever since the first version of ATT ksh 93. It isn't available in pdksh or mksh. Since ${.sh.version} is a syntax error in shells other than ksh93, wrap the test for it in a subshell. _sh_version=$(echo "${.sh.version}") 2>/dev/null case $_sh_version in '') echo "This isn't ATT ksh93";; … esac KSH_VERSION ...


4

For "real" ksh releases (i.e. AT&T based), I use this command: strings /bin/ksh | grep Version | tail -2 Here are various output I get: Original ksh: @(#)Version M-11/16/88i dtksh; @(#)Version 12/28/93 Version not defined Modern ksh93: @(#)$Id: Version AJM 93u+ 2012-08-01 $ For pdksh/msh ksh clones and modern AT&T ksh versions too, here ...


3

KSH_VERSION was not implemented in ksh93 before version 93t. It will be set in mksh, pdksh, lksh. So for checking the version of ksh, we can try these steps: Checking KSH_VERSION to detect mksh, pdksh, lksh If first step fails, try a feature that's different between ksh93 and ksh88/86 (Let David Korn show us). With these in mind, I will go with: case ...


1

mksh maintainer here ;-) though this is not the usual “support forum”… In mksh, both interactive edit (not ESC+v (vi) / ^Xe (emacs) though) is limited to single lines, as is history, as it is terminated internally by the newline character. This has always been so, even in pdksh. Apparently, pdksh in Debian was patched somehow, I see it has the ^J newline ...


0

I think you're seaching in a wrong way. I'd write such a script like this: if [ "z$STEP5" != "zOK" ] ; then expdp -your_options > $logfile & while ps ax | grep [e]xpdp ; do echo "expdp still in progress..." sleep 5 done wait # in order to be sure there is no more background processes... tail -n1 $logfile | grep ...


0

Perhaps the prompt global setting defined in /etc/profile is overwritten by the prompt user setting in ~/.profile ?


3

There are three cases: var might have been initially unset, empty, or non-empty. In the first two cases, it's set to /temp; in the last case it's left alone. Another way to do the same thing is : "${var:=/temp}" I prefer that one because the chain of assignments is clearer, but it's a matter of aesthetics. Under normal settings, this is equivalent to ...



Top 50 recent answers are included