bergman on 17 Nov 2018 16:22:31 -0800 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [PLUG] scripting help, variables in sed |
In the message dated: Fri, 16 Nov 2018 09:45:35 -0500, The pithy ruminations from Michael Lazin on [[PLUG] scripting help, variables in sed] were: => My girlfriend has a large collection of scanned family photos many of which => are different photos with the same name. We eliminated all duplicates with => fdupes, but she would like to put them all in one folder and give it to her => sisters on a cd. => => I had a bit of free time this morning and tried to write a for loop to => accomplish this but I'm getting syntax errors and I'm kinda stuck. Any => help would be appreciated. Here is my code so far: => => #!/bin/bash => var=1 => for i in *.jpg; do sed -i -e "s/"($i)"/"($var++)""($i)/" ; done i=1 ls -1 *.jpg |while read filename; do mv $filename ${i}_${filename}; i=$((i+1)) ; done Substitute "ls -1" with "find", change the target of "mv" to include a directory, etc. For bonus points...eliminate the $i variable and use options in "ls" (or "find") to preceed the target filename with the source file's inode number, guaranteeing a unique number (for a given filesystem). Or i=1 ls -1 |awk '{print "mv " $1 " " NR "_" $1}' | sh Mark => => Thanks, => => Michael => => -- => Michael Lazin => => to gar auto estin noein te kai ennai => ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug