I'm new using Unix commands in applescript. The following script you choose different folders with PDfs, get file count of PDfs on chosen folders, & write the results in text file.
Code:
set target_folder to choose folder with prompt "Choose target folders containing only PDFs to count files" with multiple selections allowed without invisibles
set results to ""
repeat with i from 1 to (count target_folder)
set thisFolder to (POSIX path of item i of target_folder)
(* 2 find searches need to be performed in order to have both total PDFs file count. One with all PDFs that DON'T start with letter R & the second others that start with letter R *)
--Find & count all PDFs in the folders selected that DON'T starts with letter R
set fileCount to do shell script "find " & quoted form of thisFolder & " -type f -name *.pdf -and -not -iname 'R[0-9-_]*.pdf' | wc -l"
-- Delimeter results before • the bullet and convert each / to a tab
set thisFolder to do shell script "echo " & quoted form of thisFolder & " | grep -o •.* | sed -e 's/•\\(.*\\):\\(.*\\)/\\1\\2/' -e 's/\\// /'g"
-->Results
set results to (results & "" & thisFolder & fileCount & return)
------------------------
--Find & count all PDFs in the folders selected that starts with letter R (RESENDS)
set fileCount to do shell script "find " & quoted form of thisFolder & " -type f -iname 'R[0-9-_]*.pdf' | wc -l"
-- Delimeter results before • the bullet and convert each / to a tab
set thisFolder to do shell script "echo " & quoted form of thisFolder & " | grep -o •.* | sed -e 's/•\\(.*\\):\\(.*\\)/\\1\\2/' -e 's/\\// /'g"
-->Results
set results to (results & "" & thisFolder & "RESENDS" & fileCount & return)
end repeat
--For testing purposes display dialog results
----------------------------------------
--write results to "PDF File Count.txt" file
set theFilePath to (path to desktop folder as string) & "PDF File Count.txt"
set theFile to open for access file theFilePath with write permission
try
set eof of theFile to 0
write results to theFile
close access theFile
on error
close access theFile
end try
When I run this section of the script I get a total PDF file count:
-
Code:
Find & count all PDFs in the folders selected that DON'T starts with letter R
set fileCount to do shell script "find " & quoted form of thisFolder & " -type f -name *.pdf -and -not -iname 'R[0-9-_]*.pdf' | wc -l"
-- Delimeter results before • the bullet and convert each / to a tab
set thisFolder to do shell script "echo " & quoted form of thisFolder & " | grep -o •.* | sed -e 's/•\\(.*\\):\\(.*\\)/\\1\\2/' -e 's/\\// /'g"
-->Results
set results to (results & "" & thisFolder & fileCount & return)
Running this section I'm NOT getting the total file PDF count for the files that starts with letter "R" which are RESENDS
Code:
--Find & count all PDFs in the folders selected that starts with letter R (RESENDS)
set fileCount to do shell script "find " & quoted form of thisFolder & " -type f -iname 'R[0-9-_]*.pdf' | wc -l"
-- Delimeter results before • the bullet and convert each / to a tab
set thisFolder to do shell script "echo " & quoted form of thisFolder & " | grep -o •.* | sed -e 's/•\\(.*\\):\\(.*\\)/\\1\\2/' -e 's/\\// /'g"
-->Results
set results to (results & "" & thisFolder & "RESENDS" & fileCount & return)
If I delete the line that delimiters the filepath results
Code:
set thisFolder to do shell script "echo " & quoted form of thisFolder & " | grep -o •.* | sed -e 's/•\\(.*\\):\\(.*\\)/\\1\\2/' -e 's/\\// /'g"
I get the results which are a total of PDFs in the chosen folders, but then I don't need the entire file path.
Hi All,
Facing an issue with grep & sed
I have logs as below:
gsc_1_20121121.log:2012-11-21 10:09:13,143 INFO - fmsspace.1 ProcessNewOrderSingleRequest: Result - ProcessNewOrderSingleBatchResultDTO - success:true,newOrderSingleBatchResults:ProcessNewOrderSingleResultDTO -... (13 Replies)
I have the following line of code that works wonders. I just don't completely understand it as I am just starting to learn regex. Can you help me understand exactly what is happening here?
find . -type f | grep -v '^\.$' | sed 's!\.\/!!' (4 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
After using the egrep command to pull certain lines from the asg5f1 (creating the asg5f1c file), I am required... (1 Reply)
The following command works perfectly in Terminal, but not in Applescript. (Returns "unknown token" error for square brackets.)
(new to site. sorry.)
I have an Applescript that is designed to find and remove any square-bracketed text, including the square brackets.
I ran the following code from... (1 Reply)
On one of my servers, it appears that a bunch of html files got the following code added to it...
I was going to try to remove this line using grep & sed... as sample
grep -lr -e 'apples' *.html | xargs sed -i 's/apples/oranges/g'
I can get the grep portion to work...
grep "<script... (7 Replies)
Hi
I am having a 'grep' headache
Here is the contents of my file:
(PBZ,CP,(((ME,PBZ,BtM),ON),((ME,((PBZ,DG),(CW9,PG11))),CW9,TS2,RT1)))
I would like to count out how many times 'PBZ' occurs and then place that number in the line above
3... (8 Replies)
I developed a script in Lingon (which is an automated script editor developed for OS X) that is used to automatically restart programs only if they crash. The script itself does just that, but I only want it to load if I'm going to use the specific application that it's designed to protect. In the... (2 Replies)
I developed a script in Lingon (which is an automated script editor developed for OS X) that is used to automatically restart programs only if they crash. The script itself does just that, but I only want it to load if I'm going to use the specific application that it's designed to protect. In... (3 Replies)
I'm trying to write a bash script to perform a tedious task, but I have no experience and hardly any knowledge so I've been having a rough time with it.
I'm on Mac OS X, and I want a script to do the following:
I have a directory that has about 200 sudirectories. In each of these directories,... (1 Reply)
hello, i'm trying to pluck words from a list that have exactly 3 occurances of a specified letter. I've come up with this :
grep -i .*$1.*$1.*$1.*
But this also selects words with 4 or more, any tips?
I'm putting this into a shell procedure and want to be able to add a switch before I put the... (1 Reply)