I have three markdown files on my machine:$ ls | grep mdbar.mdbaz.mdfoo.mdEach file has the given content:$ cat *mdi am bari am bazi am fooAs an example, I'd like loop over all the files matching the *.md pattern and print the pattern: file_name: file_contents.I'm most comfortable working with ruby. But I'd like to practice my bash for-loops and also develop my awk skills.Ruby is the easiest for me:#!/usr/bin/env ruby# iterate over all markdown files in current directoryDir.glob('*.md').each do |some_file|  puts #{some_file}: #{File.read(some_file)}endoutput:$ ./iterate_over_files.rbbar.md: i am barbaz.md: i am bazfoo.md: i am fooAnd from following the linked bash resource I created the following for-loop:#!/usr/bin/env bash# iterate over all markdown files in current directoryfor some_file in *.mddo  echo $some_file: `cat $some_file`donewhich gives the same output:$ diff <(./iterate_over_files.sh) <(./iterate_over_files.rb) # no differenceI know from watching a presentation by Brian Kernaghan and from reviewing his slides that this is a great chance to use awk because it follows the pattern:for each file  for each input line     for each pattern      if the pattern matches input line        do the actionHow do I leverage this pattern using awk and iterate over all the markdown files and print a formatted result?
How to iterate over files using awk, bash, or ruby?
bash;awk;ruby
According to the bash manual, you should use $(< FILE) rather than $(cat FILE). But there is no need to use command substitution at all:for some_file in *.mddo  echo -n $some_file:   cat $some_filedoneSince you are already aware of process substitution, you could also do something like:for some_file in *.mddo  cat <(echo -n $some_file: ) $some_filedone