E
E
eewynell2020-12-02 10:03:13
linux
eewynell, 2020-12-02 10:03:13

How to merge files, while displaying the names of these files in the end?

There are files of the format (year) - (month) - (day) (hour) - (minute) - (second).txt
They contain time codes for videos and descriptions for them
Is there a beautiful bash expression to glue them into one ? Similar format:

(год)-(месяц)-(день) (час)-(минута)-(секунда).mkv
строчка из первого файла
другая строчка из первого файла
третья строчка
(...итд)

----------------

(год)-(месяц)-(день) (час)-(минута)-(секунда).mkv
строчка из второго файла
другая строчка из второго файла
(...итд)


UPD:
I got the expression:
for i in *.txt; do echo "$i" | sed "s/txt$/mkv/; /mkv$/s/^/### /";echo;cat "$i" | awk -F" - " '!/mkv$/ && length($0) > 3 {print "**" $1 "**" " - " $2}';echo;echo "----------------";echo; done > RESULT.md

Is there a shorter / more convenient / prettier / clearer?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2020-12-02
@eewynell

Write a simple script (I have concat.sh)

#!/bin/bash

echo -e "\n--- BEGIN FILE:" $1 "\n" >> $2
cat $1 >> $2
echo -e "\n--- END   FILE:" $1 "\n" >> $2

And run
chmod a+x concat.sh
ls -1 *.txt | xargs -n 1 -I {} ./concat.sh {} out

Get what you are looking for in the out file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question