bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: count


From: John McKown
Subject: Re: count
Date: Sat, 19 Dec 2015 15:51:45 -0600

On Fri, Dec 18, 2015 at 7:05 PM, Krem <valkrem@yahoo.com> 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 three subfolders   folder1,
folder2 and folder3.
Folder1 has 4 files:   file1, file2,  file3   and file4.

The same thing is for folder2 and folder3.
Assume that file1 has 36 rows ( wc -l file1) =36.
Assume that file2 has 50 rows ( wc -l file2) =50.
Assume that file3 has 36 rows ( wc -l file3) =120.
Assume that file4 has 50 rows ( wc -l file4) =15.


I want the output
mainfolder  subfiolder   filename   # of rows

A               Folder1        file1            36
A               Folder1       file2             50
A               Folder1       file3            120
A               Folder1       file4            15
A               folder 2     filename1         ..
..
..
..
A            last_folder    lasfilename    ... .

Can anyone help me out?

Thanks in adv
​ance​


Try this and see if it is close to what you want:

find . -type f | 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

${PWD##*/} is the "mainfolder" ${PWD} is the entire name of the current directory. ##*/ eliminates all character up to, and including the _last_ / . This give you just the last node name. E.g /home/me/some/A ==> A

dirname ${i} | cut -b 3-  gives the "subfolder" name. The "cut -b 3-" cuts off the first two bytes, which is _normally_ always "./" given the syntax of the find command. You may need to mess with this.

basename ${i} just gives the file name itself, with no directory aka "filename"

wc -l -- you already know that.

the final cut command just rearranges the output into the order you wanted it to be in.


--

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]