Advertisement
sxiii

Text File Concatinator *Unite/Combine* By Special Tags

Dec 15th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.18 KB | None | 0 0
  1. #!/bin/bash
  2. ###############################################################################
  3. # This script takes two files as input: file1 (file.txt) which is in form of
  4. # hello here i am [tag]
  5. # hello [tag] world
  6. # File two (tags.txt) which is in form of
  7. # blaa blaa
  8. # blaa blaa1
  9. # And then it produces output, 3rd file (output.txt), with the results like
  10. # hello here i am blaa blaa
  11. # hello here i am blaa blaa1
  12. # hello blaa blaa world
  13. # hello blaa blaa1 world
  14. ###############################################################################
  15. # Hint: Debug lines can be removed
  16. # Hint: run like ./tags-replace.sh file.txt tags.txt output.txt
  17. ###############################################################################
  18. # by Security XIII on Dec 16 - 2014
  19.  
  20. while read -r line; do
  21. # DEBUG # echo "line is: $line"
  22.     for WORD in $line; do
  23.     # DEBUG # echo "word in line is: $WORD"
  24.         if [[ $WORD == "[tag]" ]]; then
  25.             # DEBUG # echo "found tag!"
  26.             while read -r line2; do
  27.             # DEBUG # echo "adding this to $3: $longrow $line2"
  28.             echo "$longrow $line2" >> $3
  29.             done < "$2"
  30.         else
  31.         # DEBUG # echo "adding this to longrow: $WORD"
  32.         longrow+="$WORD "
  33.         fi
  34.     done
  35. done < "$1"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement