For using cat
to output *.txt
files within a specific directory, how can I insert the filename as a "break" before each file?
file #1
contents of file
file #2
contents of file
ideally as an easy to remember few bash
commands.
see also:
For using cat
to output *.txt
files within a specific directory, how can I insert the filename as a "break" before each file?
file #1
contents of file
file #2
contents of file
ideally as an easy to remember few bash
commands.
see also:
Improved answer;
Instead of an separate -exec basename
, using just -print
will show the filename:
find . -type f -print -exec cat {} \;
You could use a find
command with multiple -exec
;
find . -type f -iname '*.txt' -exec basename {} \; -exec cat {} \;
-> ls
a.txt b.txt
-> find . -type f -iname '*.txt' -exec basename {} \; -exec cat {} \;
b.txt
b
a.txt
a
One more option to @0stone0 answer
You can use tail
insted of cat:
tail -n +1 *
Output:
==> file-1.txt <==
contents of file
==> file-2.txt <==
contents of file
if you want to search a string in list of files then this should be best option. This will print the filenames as well
grep "some string" *.log