brent timothy saner on 16 Nov 2018 06:56:13 -0800


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

Re: [PLUG] scripting help, variables in sed


On 11/16/18 9:45 AM, Michael Lazin wrote:
> 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

so first off, this isn't moving the files anywhere. it's.. not really
even doing anything, really, because you're telling sed to edit the
*contents* of a file (without even specifying a file, at that).

to answer your question indirectly you can use variables in a sed
command thusly:

export somevar="BAR"
sed -i -e "s/FOO/${somevar}/g" somefile

all instances of "FOO" in the file named "somefile" will hitherto be
changed to "BAR".

but you don't want that, because you don't want to be running sed on
JPEG files.

instead, you likely want to do (something like) this:


mkdir -p new/directory
find ./ -type f -name "*.jpg" -exec mv '{}' new/directory/. \;


no need to do sed or ...variable increments, for whatever reason, or
what have you.

Attachment: signature.asc
Description: OpenPGP digital signature

___________________________________________________________________________
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