Help with my error and logging my results

MrClick

New Member
Joined
Dec 15, 2019
Messages
1
Reaction score
0
Credits
0
I have to create folders, extract images to the folders and make a count of the image files in a file. Here is my screenshots. As you can see its having a 'same file' error and its not writing to the file
Screenshot (38).png
Screenshot (39).png
 


It looks like you might be using Microsoft Windows 10 and not Linux.

Have you tried asking on a Windows Forum?
 
It looks like you might be using Microsoft Windows 10 and not Linux.

Have you tried asking on a Windows Forum?
Looks like they're using that new fangled Linux subsystem for windows - or whatever it's called?!
Or is it the mingw terminal?? Or perhaps cygwin?
Either way - it's a perfectly valid shell-scripting question!

@MrClick :
From looking at the script - your find commands look absolutely fine.
I suspect the reason you're getting errors is - because you've already ran your script at least once and therefore already created the directories and copied the files into them.

Perhaps clean up after your script using rm -r JPG/ PNG/ TIFF/. Then try running it again.
But only once you've read the rest of this post and fixed the problems in the second half of your script.

The second half of your script, where you create your output file is completely incorrect.
First up - lose the cat command - you don't need that.
If you were looking for a command to create a new file called PictureCounts.md, then the touch command would be more appropriate. But even using touch is still unnecessary. Redirecting the output from your wc commands will be sufficient!

The way you're trying to get your line counts is completely wrong.

For starters your wc commands need to use the -l (lowercase L) parameter, not -1 (number 1). -1 isn't a valid parameter.
Also you're doing things in the wrong order. What you need to do is list the contents of each sub-directory and pipe that output to the wc utility, in order to obtain the number of lines in the listing.

At the moment, you're just passing the name of a directory to wc and passing a bogus parameter. I have no idea why you're using awk either.

What you're looking for is more like this:
Code:
echo "JPG files: $(ls JPG/ | wc -l)" > PictureCounts.md
echo "PNG files: $(ls PNG/ | wc -l)" >> PictureCounts.md
echo "TIFF files: $(ls TIFF/ | wc -l)" >> PictureCounts.md

In the above, we get the number of files in the each of the folders using a sub-shell and then echo a message and the count to PictureCounts.md via redirection.

NOTE: In the first line, we are redirecting the output using a single > which will create a new file called PictureCounts.md, or completely overwrite it, if it already exists. This will mean that the file will be completely rewritten each time the script is ran. Otherwise, each time your script is ran, your .md file will keep getting appended to.

In the subsequent lines, we use >> so that the final lines of output are appended to the end of PictureCounts.md.

And if you want to see the content of PictureCounts.md at the end of your script, perhaps add the following line at the end of the script:
Code:
cat PictureCounts.md
 

Members online


Top