#!/bin/bash ############################################################################### # This script takes two files as input: file1 (file.txt) which is in form of # hello here i am [tag] # hello [tag] world # File two (tags.txt) which is in form of # blaa blaa # blaa blaa1 # And then it produces output, 3rd file (output.txt), with the results like # hello here i am blaa blaa # hello here i am blaa blaa1 # hello blaa blaa world # hello blaa blaa1 world ############################################################################### # Hint: Debug lines can be removed # Hint: run like ./tags-replace.sh file.txt tags.txt output.txt ############################################################################### # by Security XIII on Dec 16 - 2014 while read -r line; do # DEBUG # echo "line is: $line" for WORD in $line; do # DEBUG # echo "word in line is: $WORD" if [[ $WORD == "[tag]" ]]; then # DEBUG # echo "found tag!" while read -r line2; do # DEBUG # echo "adding this to $3: $longrow $line2" echo "$longrow $line2" >> $3 done < "$2" else # DEBUG # echo "adding this to longrow: $WORD" longrow+="$WORD " fi done done < "$1"