Quantcast
Channel: Cat all files in a folder including filename by using a for loop? - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 4

Answer by Stéphane Chazelas for Cat all files in a folder including filename by using a for loop?

$
0
0
for f in *; do
  printf '%s\n' "$f"
  paste /dev/null - < "$f"
done

Would print the file name followed by its content with each line preceded by a TAB character for each file in the directory.

Same with GNU awk:

awk 'BEGINFILE{print FILENAME};{print "\t" $0}' ./*

Or to avoid printing the name of empty files:

awk 'FNR==1 {print FILENAME}; {print "\t" $0}' ./*

Or with GNU sed:

sed -s '1F;s/^/\t/' ./*

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>