Send mdfind output into script file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Send mdfind output into script file
# 1  
Old 05-09-2013
Send mdfind output into script file

I'm using mdfind to list images according to their orentation, thus:-

Code:
mdfind  " kMDItemOrientation == 1" -onlyin "/Users/me/Documents/STUDY/AskForum"

which outputs
Code:
/Users/me/Documents/STUDY/AskForum/01 (5).jpg
/Users/me/Documents/STUDY/AskForum/01 (4).jpg
/Users/me/Documents/STUDY/AskForum/01 (2).jpg
/Users/me/Documents/STUDY/AskForum/01 (1).jpg

and this
Code:
mdfind  " kMDItemOrientation == 0" -onlyin "/Users/me/Documents/STUDY/AskForum"

which outputs
Code:
/Users/me/Documents/STUDY/AskForum/01 (3).jpg



What I want to do is write the mdfind output into a script file thus:-

Code:
mv "/Users/me/Documents/STUDY/AskForum/01 (6).jpg" Ori-1
mv "/Users/me/Documents/STUDY/AskForum/01 (5).jpg" Ori-1
mv "/Users/me/Documents/STUDY/AskForum/01 (4).jpg" Ori-1
mv "/Users/me/Documents/STUDY/AskForum/01 (2).jpg" Ori-1
mv "/Users/me/Documents/STUDY/AskForum/01 (1).jpg" Ori-1


mv "/Users/me/Documents/STUDY/AskForum/01 (3).jpg" Ori-0


Can I do this from a UNIX commandline in Terminal on Mac OS X 10.7.5


Ta

waggs
# 2  
Old 05-13-2013
Seems pretty simple:
Code:
$ mdfind ... | while read f
do
 mv "$f" dest_dir
done

# 3  
Old 05-13-2013
Perfect. Thanks.
# 4  
Old 05-14-2013
That's a shell keeper, and you can read N+ fields into N variables, you can change $IFS in the while subshell to change field dividers, it has low latency and no upper limit on lines processed. It works in bash, ksh, and who knows, maybe sh. Avoid "for f in `make_all_files`; do ... done". Bash has a read -a to load all fields into one predefined typedef array variable.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run a script before and after reboot automatically and send output to two locations.

Hello Team . I am working a health check script ( bash) to run on linux server ( RedHat) and requirements are 1. The o/p of script need to be send to two diff files . I am testing with tee command . But I am not successful yet , any recommendations if that is the right approach ? 2. The same... (2 Replies)
Discussion started by: Varja
2 Replies

2. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

3. Shell Programming and Scripting

Send output of time command to file

I am measuring the time it takes for a wget command to complete. Right now my command is: time wget https://`ifconfig -a | grep '32.29.120' | cut -d: -f2 | cut -d' ' -f1`:8443/primary-rest/shop?brandId=test --header="name: test" --no-check-certificate -o SELF_TEST.log The output I get is ... (2 Replies)
Discussion started by: Junaid Subhani
2 Replies

4. Shell Programming and Scripting

Compare 2 files the send output to a file

Hallo Friends, I would like to compare two files, then write the difference between the two into output file then find a pattern then search for that pattern. -bash-3.2$ cat BS_Orig_20141112.csv|head -20 BW0159574451211141638275086@196.35.130.5 BW02043750712111491637691@196.35.130.5... (2 Replies)
Discussion started by: kekanap
2 Replies

5. Shell Programming and Scripting

How to write this script:- check output word and send a mail?

Hi Guys, I am not Good at scripting. I need to write a script such that if output of command shows the particular word in output then send mail to abc@compay.com -bash-3.2$ ps -ef | grep bpbkar root 6040 1 0 13:05:19 ? 0:00 bpbkar -r 2678400 -ru root -dt 47395 -to 0... (20 Replies)
Discussion started by: manalisharmabe
20 Replies

6. Shell Programming and Scripting

Read file, send to dig, no output

From the command line I am running the following command: for i in $(awk '{print ($1)}' src-dst|uniq); do dig -x "$i" +short; done src-dst has a list of IP addresses. When this script is running and I do a ps -ef | grep dig, I see the proper dig command with IP addresses being run, but the... (2 Replies)
Discussion started by: phish
2 Replies

7. Shell Programming and Scripting

rm output from mdfind

I am trying to delete all aliases from a specific location. so far i have: rm -f `mdfind -onlyin /Users/steve/Desktop/Test 'kMDItemKind=Alias' /` i thought this would delete all files that were Aliases using ItemKind, but it will not delete the files. However, doing just mdfind -onlyin... (0 Replies)
Discussion started by: slindgre
0 Replies

8. Shell Programming and Scripting

send an email of script output

Hi All, I'm trying to send some file which generated by script to my email. when I run the script I'm getting an email. Thats fine. But it seems to be all messed up like below Memory Status on ServerA: Mem: 3867444k total, 862680k used, 3004764k free, 54456k buffers!! CPU Status on ServerA:... (4 Replies)
Discussion started by: s_linux
4 Replies

9. Shell Programming and Scripting

capture output of file and send last string thereof to new file

Hello, If I run a program from within shell, the output is displayed in the command line terminal. Is there a way I can capture that output and choose only the very last string in it to send it to a new file? Thank you (6 Replies)
Discussion started by: Lorna
6 Replies

10. Shell Programming and Scripting

Easiest way to send output to a debug file?

I have this in my script: DEBUG_DIR=/log/rotate_output DEBUGLOG=${DEBUG_DIR}/rotate.${TIMESTAMP} SERVER_FILE_LIST="\ wasint0206 /logs/squid_backup wasint0201 /logs/squid_backup" /usr/bin/echo "${SERVER_FILE_LIST}" | while read SERVER DIRECTORY do cd /log/squid_logs/${SERVER}... (2 Replies)
Discussion started by: LordJezo
2 Replies
Login or Register to Ask a Question