سؤال

I'm using a few commands to cat a few files, like this:

 cat somefile | grep example | awk -F '"' '{ print $2 }' | xargs cat

It nearly works, but my issue is that I'd like to add a newline after each file.

Can this be done in a one liner?

(surely I can create a new script or a function that does cat and then echo -n but I was wondering if this could be solved in another way)

هل كانت مفيدة؟

المحلول

cat somefile | grep example | awk -F '"' '{ print $2 }' | while read file; do cat $file; echo ""; done

نصائح أخرى

Using GNU Parallel http://www.gnu.org/software/parallel/ it may be even faster (depending on your system):

cat somefile | grep example | awk -F '"' '{ print $2 }' | parallel "cat {}; echo"

awk -F '"' '/example/{ system("cat " $2 };printf "\n"}' somefile

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top