New answers tagged

0

I don't think find has an option like this, you could build a command using printf and your exclude list: find . -name "*.txt" $(printf "! -name %s " $(cat file.txt)) -mtime +60 -exec rm -f {} + file.txt will have list of files to exclude in find command.


1

Assuming your files have sane names (i.e. they don't have embedded newlines), something like this should work: find . -mtime +60 | fgrep -v -x -f exceptions.txt | xargs -d '\n' rm -f Replace rm -f with ls -1 for a dry run first. Put paths exactly as they are printed by find in exceptions.txt.


2

Turns out it is documented behaviour. From the ksh93 man page: Search Edit Commands These commands access your command history. [count]k Fetch previous command. Each time k is entered the previous command back in time is accessed. [count]- Equivalent to k. [count][A If cursor is at the end of the line it is equivalent to / ...


0

My understanding is that prior to RHEL 6, Red Hat were wary of the AT&T KornShell because of its licence, so they included the pdksh, which is a less complete implementation. I think David Korn was doing his best to get ksh accepted in as many places as possible and somewhere along the line the licence was clarified or changed. This quote is from the ...


10

Ksh93 does a lot to avoid forks. I have no idea how it knows how to handle the first case, as a truss shows that it only calls one write(2) call with the final result. It may be that David scans the command in macro.c and knows that he may handle "echo" internally. What I can say is that I rewrote the parser and the interpreter of the "Bourne Shell" last ...


0

The best way that I have found is to use a ksh93 discipline function on the PS1 environmental variable: # set ksh prompt and xterm title _PSX='$( p="${PWD/~(El)${HOME}/\~}" printf "%s@%s:%s" "${LOGNAME}" "$(hostname -s)" "${p}" )' function PS1.get { .sh.value="ESC]0;${_PSX}^G${_PSX}$ " }


1

That's because underscore _ is a valid part of a variable name, so you also need the curly braces around FILENAME: NAME=${FILENAME}_${mdate}_${EXTENSION} Based on your other response, it appears that you also have a carriage return (\r) in either the FILENAME assignment line or the output of sqlplus, in $mdate. Find out which by running cat -v on your ...


0

There's probably a more elegant way to do this, but you could pull your desired variables from that remote file into a local temporary file: file=/tmp/tempfile.$RANDOM ## AIX doesn't come with mktemp > $file || echo Failed to pick a good tempfile name grep "export CONFIG.=" some-file > $file Then use the . builtin to read that file: . $file and ...


1

magic_script dirdata dirfinal file1.txt $0 is the script_name (magic_script) $1 first argument dirdata $2 second argument dirfinal $3 third argument file1.txt ftp -divn XXX.XXX.XX0 << EOF! user user pass cd /home/dir1/dir2/dir3/"$1" lcd/home/dir11/dir22/dir33/"$2" get "$3" bye EOF!


0

I have found the solution: perl -MPOSIX -le 'print strftime ""%Y%m%d%H%M%S", localtime((lstat)[9]) for @ARGV' file.txt


1

To replace newlines embedded in records with spaces using GNU awk. num_fields=4 awk -v RS='([^|]*\\|){'"$num_fields"'}[^|]*\n' ' { n = split(RT, a,"|"); for (i=1; i<=n; ++i) { gsub("\n", " ", a[i]); printf "%s%s", a[i], i==n?"\n":"|" } }' file This gives 1|ABC|11|DEF|111 2|ABC|22|PQR ST UW|222 3|ABC|33|XYZ|333 4|ABC|44|...


1

The stat command is not standard. There's one on Linux, a more restricted one on embedded Linux, one with completely different options on FreeBSD and OSX, and none on most other Unix variants such as Solaris, AIX, and HP-UX. Your syntax looks like it's intended for Linux's stat. You're apparently running a system without stat. You probably don't have date -...


0

One way of picking up the pieces from this insane file format is with Perl. #!/usr/bin/perl # use warnings; use strict; undef $/; my $file = <>; while ($file =~ /^(.*?\|.*?\|.*?\|.*?\|.*?)$/mscg) { my $fields = $1; $fields =~ s/\n(.)/\\n$1/sg; print "$fields\n"; } The code slurps the entire file into memory, and then reblocks it on ...


0

It depends completely on your system, which you did not specify. An alternative to installing the binary provided by your package manager is to compile the program from source. To do so, you must first download the coreutils source (coreutils-8.0 at the time of writing). If it is in an archive, unarchive it and then enter into the directory of the source. ...


1

Pretty sure your error is meant to indicate that your shell: /usr/bin/ksh: Can't find "stat": stat: not found Does your operating system provide the "stat" command? You'll need to provide more information on your operating system and it's version for further guidance. You may also have a problem in your "PATH" environment variable.


2

grep -lZ max graham/quant/*.biz | xargs -0r maximum.sh grep -lZ milan graham/quant/*.biz | xargs -0r milan.sh grep -lZ min graham/quant/*.biz | xargs -0r minimum.sh Note: requires GNU grep for the -Z option to output NUL-separated filenames. These lines use grep's -l option to output a list of files containing the wanted pattern (max, milan, or min), ...


1

As the users says it is using an ancient unix shell, lets try another version of the script: #!/bin/sh #test version for ancient shell. cd graham/quant for file in *.biz do grep -q "max" "$file" if [ "$?" = "0" ]; then maximum.sh "$file" fi grep -q "milan" "$file" if [ "$?" = "0" ]; then milan.sh "$file" fi grep -q "min" "...


0

When should I assign double quotes around variables like "${var}" to prevent problems caused by spaces? Implicit in this question is Why isn’t ${variable_name} good enough? ${variable_name} doesn’t mean what you think it does … … if you think it has anything to do with problems caused by spaces (in variable values). ${variable_name} is good for this:...



Top 50 recent answers are included