0
1
On the second day, I'm trying to find a solution.
There is a CCC directory; we include subdirectories with numbers 1 2 3 ... 500, in each subdirectory there is a file named A1, containing one word (example) apple banana pear pineapple
$ CCC /
/1/A1.txt pear
/2/A1.txt apple
/3/A1.txt banana
/4/A1.txt pineapple
The flash BBB directory contains the ALLIN.txt
file containing the following lines:
pear is a very sweet fruit
potatoes are very high in calories
pineapple number 1 for weight loss
raspberries tasty and healthy
everyone likes strawberries !!!
So my question is:
how to find and replace occurrences of the first word in a CCC file from a BBB file so that
CONCLUSION
$ CCC /
/1/A1.txt pear a very sweet fruit
/4/A1.txt Pineapple No. 1 lose weight
and files
/ 2
/ 3
delete
I had tried:
for i in `find ./ -depth -type d ! -wholename './'`
do
join -j1 -o <${i}(sort A1.txt) <${i}(sort BBB.txt)
done
and
for i in `find ./ -depth -type d ! -wholename './'`
do
awk 'NR==FNR{a[$0];next} ($0 in a)' A1.txt BBB.txt
perl -lane '$t+=1; $h{$F[0]}=$F[1] if $.==$t; print $F[0]," ",$h{$F[0]} if $t!=$.;$.=0 if eof' $(find -name '*A1.txt') BBB.txt
I'm still learning Linux, so please, be kind to me.
Your last for-loop seems to be missing a "done". You may like to fix this. – zx485 – 2020-03-01T00:14:36.233
pear is a very sweet fruit
andpear a very sweet fruit
are two different strings. The same forpineapple number 1 for weight loss
andPineapple No. 1 lose weight
. Should they be the same? Or is there another layer of conversion you forgot to mention? – Kamil Maciorowski – 2020-03-01T06:57:21.863Bash pitfall number 1. – Kamil Maciorowski – 2020-03-01T07:05:10.313