I have two input files:
File1.txt:
Name Latin-small Roman Latin-caps #header, not to be processed
F0, a, I, A
F1, b, II, B
F2, c, III, C
F3, d, IV, D
File2.txt:
Lorem ipsum
Roman here.
LCaps here.
LSmall here.
Lorem ipsum
- I get assign values of
R
,LC
andLS
from each line ofFile1.txt
(line 6 ofscript.sh
). - Generate folders named
Fx
, where x=0, 1, 2, 3,... usingFile1.txt
(line 7 ofscript.sh
). - Individual files named
Fx.txt
, generated usingFile2.txt
has to be placed in those folder (line 7 ofscript.sh
). - Now, after reading a signle line of
File1.txt
, it should read (line 7 ofscript.sh
) & modify the wholeFile2.txt
looking at the keys. <- this is where I cannot make it work, it reads one line ofFile2.txt
for each line ofFile1.txt
. - The contents of those files are basically copies
File.txt
, except the values ofhere
, modified using the keysRoman
($3 ofFile1.txt
),LCaps
($4 ofFile1.txt
) andLSmall
($2 ofFile1.txt
) for eachFx.txt
in each directory, using the values assigned in the first step fromFile1.txt
(line 9-17 ofscript.sh
).
How to get the following output in respective folders (e.g. the output file in Folder F2
), using awk:
cat F0/F0.txt
Lorem ipsum
Roman I.
LCaps A.
LSmall a.
Lorem ipsum
or,
cat F3/F3.txt
Lorem ipsum
Roman IV.
LCaps D.
LSmall d.
Lorem ipsum
or,
cat F2/F2.txt
Lorem ipsum
Roman III.
LCaps C.
LSmall c.
Lorem ipsum
More info: File1
is ~300lines, for each line (except the header), one file is to be created in each folder. File2
is ~200lines. Each of the phrases Roman
or LSmall
or LC
randomly occur in certain lines of File2.txt
, but not more than one in one line. These are the keys for modyfying values in `
Thanks in advance! This question is a part of a bigger workflow.
EDIT2: trial code
script.sh
awk 'BEGIN {FS=","}
{
if ($1 !~ "F")
{}
else if ($1 ~ "F")
{LS = $2; R = $3; LC = $4;
system("mkdir "$1); filename=$1"/"$1".txt";
{(getline < "File2.txt");
{
if ($0 ~ "Roman")
{gsub("here",R); print >> filename;}
else if ($0 ~ "LSmall")
{gsub("here",LS); print >> filename;}
else if ($0 ~ "LCaps")
{gsub("here",LC); print >> filename;}
else
{print >> filename;}
}
}
}
}
' File1.txt
I'm getting folder and file structure as I need (file Fx.txt
in Folder Fx
, where x = 0, 1, 2, ...), but content of these files are:
cat F0/F0.txt
Lorem ipsum
cat F1/F1.txt
Roman II.
cat F2/F2.txt
LCaps C.
cat F3/F3.txt
LSmall d.
The key is to make awk
read the entire file2.txt
, while reading each line of file1
and making modifications and placing the new files in respective folders.