简体   繁体   中英

How to collect all README files and rename them in a folder?

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!

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}'
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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM