I've got a relatively small list of filenames generated from a pipeline based on find
. The file names contain spaces and possibly punctuation but definitely no other non-printing characters or newlines.
For example,
Netherlands/Purge (GDPR) 2020-01-09.txt
Netherlands/Purge (GDPR) 2020-01-27.txt
Switzerland/New mailing 2020-01-27.txt
I want to edit these files as a set (vi file1 file2 file3
rather than vi file1; vi file2; vi file3
), partly so that I can easily jump forwards and backwards between them.
I've started with Using a generated list of filenames as argument list — with spaces
, which has a standard find -print0 | xargs -0 mycommand
solution. Unfortunately this does not work when mycommand
is an editor because although xargs
can assemble the set of files to edit, stdin is already taken up from the pipeline and I can't see a way to run an editor in-place. I can't use find -exec vi {} +
because I'm using a pipeline to validate the set of filenames, and not just find
itself.
My other option is to copy and paste, assembling the list of file names, surrounding them with quotes, and then prefixing the result with vi
. For these three files it's trivial, but in the general case it's not an easily-reusable solution,
vi 'Netherlands/Purge (GDPR) 2020-01-09.txt' 'Netherlands/Purge (GDPR) 2020-01-27.txt' 'Switzerland/New mailing 2020-01-27.txt'
Given a GNU/Linux platform with bash
as my preferred shell (in case it matters), how can I edit a similarly generated list of files?
find | something | xargs vi
with something likefind -exec something -exec vi
? – pLumo Jul 10 '20 at 14:34find -type f -mtime +14 -mtime -22 -iname '*.xml' | while IFS= read -f x; do xmlstarlet sel -T -t -v '//magicElement -n "$x" | grep -q magicValue && echo "$x"; done
– Chris Davies Jul 10 '20 at 14:37