I have a text file that holds a list of files. I want to cat their contents together. What is the best way to do this? I was doing something like this but it
xargs
The advantage of xargs over $(cat) is that cat expands to a huge list of arguments which could fail if you have a lot of files in the list:
printf 'a\nb\n#c\n' > files
printf '12\n3\n' > a
printf '4\n56\n' > b
printf '8\n9\n' > c
# Optional grep to remove lines starting with #
# as requested by the OP.
grep -v '^#' files | xargs cat
Output:
12
3
4
56
Related: How to pipe list of files returned by find command to cat to view all the files