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" in the proper order to avoid it whining at me. And to use the proper value of "2" instead of "1" in the -mindepth and -maxdepth arguments. my bad for not testing first. I had to change the egrep to put the ^ at the front of the pattern to "anchor" it at the start of the line created by "find". OK, it probably would have run correctly without it, but I'm a bit anal about such things. On Mon, Dec 21, 2015 at 7:45 AM, John McKown <john.archie.mck...@gmail.com> wrote: > 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 > (which is where I read most of my email - can't stand email on tablet). > > On Sun, Dec 20, 2015 at 8:12 PM, Krem <valk...@yahoo.com> wrote: > >> >> John, >> >> After trail and error the following works for me but still has to be >> refined. >> >> find . -type f | while read i; do echo -e "$(dirname ${i}}} | cut -b 3-) >> $(basename ${i}) $(wc -l ${i})" ; done | cut -d " " -f 1,2,3 >> >> >> 1. All the folders that I am interested in are all starts with number >> 2. I don/t want to go in sub folders >> 3. Using the above script the results look like teh following >> >> 185 name.csv 6506 >> 186 add.csv 480 >> 187 31851513 65 >> 188 add.csv 44131 >> 189 add.txt 44131 >> Name 1692157077 >> > > for points #2 & 3: > examine the "find" command closely. You can do something like: > > find . -type f -name '*.csv' -o -name '*.txt' -maxdepth 1 -mindepth 1 > > -type f # find only regular files (no directories, sockets, or other weird > stuff) > -name '*.csv' -o -name '*.txt' # whose names end with .csv or .txt > -maxdepth 1 # don't look in sub- sub-directories > -mindepth 1 # don't look in this directory. > # the two together say to only look at files in the directories > immediately below this directory. > > Unfortunately you can't do point #1 in the find command itself. So you > must "subset" it before doing the "do" loop. Something like: > > find . -type f -name '*.csv' -o -name '*.txt' -maxdepth 1 -mindepth 1 |\ > 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 > > The find scans all direct subdirectories (1 level down only) for regular > files with a .txt or .cvs suffix. > The egrep looks for directories which start with a "./" (which is what > find prefixes them with) followed by a digit. Other characters after that > can be anything > The 3rd line is the "do" loop that actually produces output. > > > >> >> the first column is the folder name >> the second column is the file name >> the last column is the count >> >> ****Row 3 and 5 must be excluded because they don't have proper file >> name >> and also the 5th column does not start with number. >> >> I want to split the output into two files >> File one contains only add* and file two should contain name*. >> >> I reach to my goal on teh fourth step. >> >> Here are thesteps >> >> #Step 1 >> >> find . -type f | while read i; do echo -e "$(dirname ${i}}} | cut -b 3-) >> $(basename ${i}) $(wc -l ${i})" ; done | cut -d " " -f 1,2,3 > xyz >> >> #Step 2 >> grep -e "Name" xyz |sort | uniq -c > X_Name >> >> #step 3 >> grep -e "Add" xyz |sort | uniq -c > X_Add >> >> #Step 4 >> join -1 2 -2 2 x_Name X_Add > Want_all >> >> ## 2 is the folder name , where the two files are joind together. >> >> Do you think there better way of doing this? >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> -- >> View this message in context: >> http://gnu-bash.2382.n7.nabble.com/count-tp16675p16683.html >> Sent from the Gnu - Bash mailing list archive at Nabble.com. >> >> > > > -- > Computer Science is the only discipline in which we view adding a new wing > to a building as being maintenance -- Jim Horning > > Schrodinger's backup: The condition of any backup is unknown until a > restore is attempted. > > Yoda of Borg, we are. Futile, resistance is, yes. Assimilated, you will be. > > He's about as useful as a wax frying pan. > > 10 to the 12th power microphones = 1 Megaphone > > Maranatha! <>< > John McKown > -- Computer Science is the only discipline in which we view adding a new wing to a building as being maintenance -- Jim Horning Schrodinger's backup: The condition of any backup is unknown until a restore is attempted. Yoda of Borg, we are. Futile, resistance is, yes. Assimilated, you will be. He's about as useful as a wax frying pan. 10 to the 12th power microphones = 1 Megaphone Maranatha! <>< John McKown