Re: [patch] new special variable: test argument

2015-12-21 Thread Greg Wooledge
On Sat, Dec 19, 2015 at 12:58:41AM +0100, Piotr Grzybowski wrote: > #2 > touch /tmp/`date +%s`; if [ -f /tmp/`date +%s` ]; then echo "ok: $^"; fi; This is both wrong (insecure) and clumsy. You can't create a temp file this way. If the file already existed, then you're using someone else's booby

Re: [patch] new special variable: test argument

2015-12-21 Thread Greg Wooledge
On Sat, Dec 19, 2015 at 01:03:35AM +0100, Piotr Grzybowski wrote: > On Wed, Dec 16, 2015 at 7:36 PM, Stephane Chazelas > wrote: > > What's wrong with > > > > f=/tmp/myfile; [ -f "$f" ] && { echo "$f is here"; head -n 1 < "$f"; } > > nothing. sometimes it is just not practical (see my answer to C

Re: count

2015-12-21 Thread John McKown
Sorry about delay, for some reason Google put your emails in SPAM. Also, I don't really read much email on Sunday. I was "busy" building up my planets in GOFA after church. And watching some TV. Pretty much didn't think about email at all, because I do all that "other stuff" on my tablet, not my PC

Re: count

2015-12-21 Thread John McKown
OOPS, slight correction: find . -maxdepth 2 -mindepth 2 -type f -name '*.csv' -o -name '*.txt' |\ egrep '^\./[0-9]' |\ while read i;do echo -e "${PWD ​##​*/ } $(dirname ${i ​ } ​ | cut -b 3-​ ) $(basename ${i}) $(wc -l ${i})" ;done | cut -d " " -f 1,2,4,3 I needed to put the arguments to "find"

Re: count

2015-12-21 Thread John McKown
On Fri, Dec 18, 2015 at 7:05 PM, Krem wrote: > Hi all, > > I have one folder and this folder contains several folders. Each sub > folders > contains 5 or 6 files. So i want count the number of rows within each > file and produce an output. > > Assume the main folder called A and it has th

Only one Friday 13th coming in 2016

2015-12-21 Thread Bill Duncan
We had 3 this year.. $ for y in {1950..2050} ; do for m in {1..12};do cal $m $y|awk 'FNR==1{m=$0}/^ 1/{print m}';done;done| awk '{a[$2]=a[$2]" "$1}END{for (i in a) print i,a[i]}'| sort| awk '{t=$1;$1="";a[$0]=a[$0]" "t}END{for (i in a) printf "%-24s %s\n", i, a[i]}' | sort | cat -n 1 Ap

Re: count

2015-12-21 Thread Greg Wooledge
On Mon, Dec 21, 2015 at 07:58:02AM -0600, John McKown wrote: > OOPS, slight correction: > > find . -maxdepth 2 -mindepth 2 -type f -name '*.csv' -o -name '*.txt' |\ > egrep '^\./[0-9]' |\ > while read i;do echo -e "${PWD > ???##???*/ > } $(dirname ${i > ??? > } > ??? | cut -b 3-??? > ) $(basenam

Re: count

2015-12-21 Thread Greg Wooledge
On Mon, Dec 21, 2015 at 08:21:04AM -0600, John McKown wrote: > find . -maxdepth 2 -mindepth 2 -type f -name '*.csv' -o -name '*.txt' |\ > egrep '^\./[0-9]' |\ > xargs awk 'ENDFILE {print FILENAME "\t" FNR;}' |\ > sed -r 's|^./||;s|/|\t|' |\ > xargs -L 1 echo -e "${PWD##*/}\t"??? > ???This is "mo

Re: Only one Friday 13th coming in 2016

2015-12-21 Thread John McKown
Gee bit too much free time??? But it is interesting. On Sun, Dec 20, 2015 at 10:59 PM, Bill Duncan wrote: > We had 3 this year.. > > $ for y in {1950..2050} ; do for m in {1..12};do cal $m $y|awk > 'FNR==1{m=$0}/^ 1/{print m}';done;done| awk '{a[$2]=a[$2]" "$1}END{for (i > in a) print i,a[i]}'|

Re: count

2015-12-21 Thread John McKown
Thanks for the training. I appreciate people pointing out my errors, that's how I learn too. I'll blame GMAIL for the mish-mash. I don't have as good a control of it as I would like (sorry). I'm always forgetting about people who put LFs in a file name. That is just so weird, to me. I should rememb

Re: Only one Friday 13th coming in 2016

2015-12-21 Thread Allodoxaphobia
On Sun, 20 Dec 2015 23:59:32 -0500, Bill Duncan wrote: > We had 3 this year.. > > $ for y in {1950..2050} ; do for m in {1..12};do cal $m $y|awk > 'FNR==1{m=$0}/^ 1/{print m}';done;done| awk '{a[$2]=a[$2]" "$1}END{for (i in > a) print i,a[i]}'| sort| awk '{t=$1;$1="";a[$0]=a[$0]" "t}END{for (i in

Re: Only one Friday 13th coming in 2016

2015-12-21 Thread Greg Wooledge
On Mon, Dec 21, 2015 at 02:59:20PM +, Allodoxaphobia wrote: > Is the logic exhaustive ? -- in that it shows there > are no years with *no* Friday The 13Th's? The Gregorian calendar has 14 different year layouts: 7 non-leap-years beginning with Sunday through Saturday, and 7 leap-years beginni

Re: [patch] new special variable: test argument

2015-12-21 Thread Piotr Grzybowski
On Mon, Dec 21, 2015 at 2:21 PM, Greg Wooledge wrote: > On Sat, Dec 19, 2015 at 12:58:41AM +0100, Piotr Grzybowski wrote: >> #2 >> touch /tmp/`date +%s`; if [ -f /tmp/`date +%s` ]; then echo "ok: $^"; fi; > > This is both wrong (insecure) and clumsy. You can't create a temp file > this way. [..]

Re: [patch] new special variable: test argument

2015-12-21 Thread Piotr Grzybowski
On Mon, Dec 21, 2015 at 2:27 PM, Greg Wooledge wrote: > > If you are trying to advocate for a new feature in bash, it would behoove > you to use an example that ACTUALLY DEMONSTRATES how it would be useful. > Not a bogus example in which the feature is not only unnecessary, but > harmful as well.

Re: count

2015-12-21 Thread Krem
Hi all, Thank you very much for providing me more information, I am getting more confused. but learning more. I tried this one, but failed if the folder has more than one file name (eg *.csv) in that folder. find . -maxdepth 2 -mindepth 2 -type f -name '*.csv' -o -name '*.txt' |\ egrep '^\./[0

Re: count

2015-12-21 Thread Greg Wooledge
On Mon, Dec 21, 2015 at 08:53:55AM -0700, Krem wrote: > I tried this one, but failed if the folder has more than one file name (eg > *.csv) in that folder. Seriously, use this one: find . \( -iname '*.txt' -o -iname '*.csv' \) -exec bash -c ' for f; do IFS=/ read -ra part <<< "$f" print

Re: count

2015-12-21 Thread John McKown
I've "squirreled" that one away on GitHub, in a gist. Thanks. On Mon, Dec 21, 2015 at 11:00 AM, Greg Wooledge wrote: > On Mon, Dec 21, 2015 at 08:53:55AM -0700, Krem wrote: > > I tried this one, but failed if the folder has more than one file name > (eg > > *.csv) in that folder. > > Seriously,

Re: count

2015-12-21 Thread Krem
Here is another problem with the following script find . \( -iname '*.txt' -o -iname '*.csv' \) -exec bash -c ' for f; do IFS=/ read -ra part <<< "$f" printf "%-10.10s %-10.10s %-20.20s %5d\n" \ "${part[1]}" "${part[2]}" "${part[3]}" "$(wc -l < "$f")" done ' _ {} + _: -c

Feature discussion - startup files

2015-12-21 Thread Chet Ramey
I've been approached by some HPC system administrators (who have the unenviable task of supporting thousands of users) who have requested a new feature in bash: a system startup file with a fixed name (e.g., /etc/bashenv) that is sourced by every instance of bash. The initial request was for somet

Re: Why I love bash scripting?

2015-12-21 Thread Chet Ramey
On 12/20/15 8:44 AM, ken.w.mar...@gmail.com wrote: > next, please run >> bashdb test.sh > bashdb<0> n > bashdb<1> n > bashdb<2> n > bashdb<3> print ${BASH_REMATCH[0]} > > and you will see that in bashdb BASH_REMATCH is an empty string. It appears > the debugger is broken and has probably been so

Re: Feature discussion - startup files

2015-12-21 Thread Piotr Grzybowski
Hey, As an administrator, when I faced this issue I usually used some wicked sourcing in standard bash startup files to get one global file that gets sourced by default (last time I wanted one per group of users, etc). It would be useful; at least for me. How much harm can it do? If the file is

Re: Feature discussion - startup files

2015-12-21 Thread Ángel González
Chet Ramey wrote: > The current configurable startup file options are insufficient for > their purposes because they can be enabled or disabled by vendors, > and these folks would rather not modify the "vendor" parts of the > system. In some cases, with some Linux distributions, doing so voids > th

Re: Only one Friday 13th coming in 2016

2015-12-21 Thread Bill Duncan
Remember that while there are 14 patterns of years, leap years don't impact Friday the 13th for January/February.. This isn't an exhaustive analysis, but a quick check for 300 years didn't show any years without a Friday 13th.. ;-) $ for y in {1900..2199} ; do for m in {1..12};do cal $m $y|awk '

Re: Only one Friday 13th coming in 2016

2015-12-21 Thread Ángel González
Bill Duncan wrote: > Remember that while there are 14 patterns of years, leap years don't > impact Friday the 13th for January/February.. > > This isn't an exhaustive analysis, but a quick check for 300 years > didn't show any years without a Friday 13th.. > > ;-) > > $ for y in {1900..2199} ; d