I have 135 documents stored as 135 lines (So each line is a long text) in File_A and I have 15 phrases in File_B. I need to extract a sentence and its before from File_A with a matching phrase in File_B. The extracted sentences from File_A-Line_1 should be output to a new file File_1. Similarly the extracted sentences from File_A-Line_2 should be output to a new file File_2 and so on till i extract matching sentences from all the lines. I did this with the following code
i=1
while read line; do
while read row; do
cat "$line" | sed 's/\./.\n/g' | grep -i -B 1 "$row" | tr -d '\n' | sed 's/--/\n/g' >> file_$i
done < $2
$i = $i+1;
done < $1
The problem here is, the output is being printed on to the console but not to the new file. Could some one help me in realizing my error.
Thank you
cat "$line"would fail straight away since$lineis a line in a text and not a filename.cat: something something...: No such file and directoryandcommand not found