The lazy me is thinking about adding a column to some textfiles.
The textfiles are in directories and I would like to add the directory name to the text file.
Like the text file text.txt
in the folder the_peasant
:
has a wart
was dressed up like a witch
has a false nose
would become:
the_peasant has a wart
the_peasant was dressed up like a witch
the_peasant has a false nose
Then I have similar text files in other folders called "the_king" etc.
I would think this is a combination of the find command, bash scripting and sed but I cant see it through. Any ideas?
This might work for you:
find . -name text.txt | sed 's|.*/\(.*\)/.*|sed -i "s@^@\1 @" & |' | sh
or if you have GNU sed:
find . -name text.txt | sed 's|.*/\(.*\)/.*|sed -i "s@^@\1 @" & |e'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With