0

For example, I have these files:

/Applications/Emacs.app/Contents/Resources/etc/images/custom/README
/Applications/Emacs.app/Contents/Resources/etc/images/ezimage/README
/Applications/Emacs.app/Contents/Resources/etc/images/gnus/README
/Applications/Emacs.app/Contents/Resources/etc/images/gud/README
/Applications/Emacs.app/Contents/Resources/etc/images/icons/README

I want to collect all of them and save them with different names in one directory, so they become something like this:

/dest/custom_README
/dest/ezimage_README
/dest/gnus_README
/dest/gud_README
/dest/icons_README

I know find and xargs might be useful to do this job but don't know how to do the rename step according to its directory name.

Does anyone have ideas about this? Thanks!

Hanfei Sun
  • 45,281
  • 39
  • 129
  • 237

2 Answers2

0

How about this:

[cnicutar@fresh ~]$ sed -r <file 's|.*images/(.*)/(.*)|\1_\2|g'
custom_README
ezimage_README
gnus_README
gud_README
icons_README

Or using awk:

awk < file -F'/' '{print $(NF-1)"_"$NF}'
cnicutar
  • 178,505
  • 25
  • 365
  • 392
0
find /Applications/Emacs.app/Contents/Resources/etc/images -name README |
while IFS= read -r filename; do
    cp -v "$filename" /dest/"$(basename "$(dirname "$filename")")_README"
done
glenn jackman
  • 238,783
  • 38
  • 220
  • 352