fork download
  1. #!/bin/bash
  2.  
  3. t=$(mktemp -t -d awkinator2.XXXXXXXXXX) || exit
  4. cd "$t"
  5. trap 'rm -rf "$t"' EXIT ERR
  6.  
  7. cat <<\: >file1.txt
  8. Name Latin-small Roman Latin-caps
  9. F0 a I A
  10. F1 b II B
  11. F2 c III C
  12. F3 d IV D
  13. :
  14.  
  15. cat <<\: >file2.txt
  16. Lorem ipsum
  17. Roman here.
  18. LCaps here.
  19. LSmall here.
  20. Lorem ipsum
  21. :
  22. # Trim the obnoxious header
  23. tail -n +2 file1.txt |
  24. while read -r directory LSmall Roman LCaps; do
  25. mkdir "$directory"
  26. awk -v LSmall="$LSmall" -v Roman="$Roman" -v LCaps="$LCaps" '
  27. BEGIN { split("LSmall:Roman:LCaps", k, /:/)
  28. split(LSmall ":" Roman ":" LCaps, r, /:/) }
  29. {
  30. for (j=1; j<=3; ++j)
  31. if ($0 ~ k[j]) {
  32. gsub(/here/, r[j])
  33. break
  34. }
  35. }1' file2.txt >"$directory"/"$directory".txt
  36. done
  37.  
  38. tail */*.txt
Success #stdin #stdout 0s 4284KB
stdin
Standard input is empty
stdout
==> F0/F0.txt <==
Lorem ipsum
Roman I.
LCaps A.
LSmall a.
Lorem ipsum

==> F1/F1.txt <==
Lorem ipsum
Roman II.
LCaps B.
LSmall b.
Lorem ipsum

==> F2/F2.txt <==
Lorem ipsum
Roman III.
LCaps C.
LSmall c.
Lorem ipsum

==> F3/F3.txt <==
Lorem ipsum
Roman IV.
LCaps D.
LSmall d.
Lorem ipsum