I am trying to work out how I can add the contents of a set of files1 defined by
ls /home/dir1/*-split.csv.*
And then add the contents of each file from files1 into another set of files e.g. files2 defined by
ls /home/dir2/*.py.*.py
Both sets of files1 and files2 will always have the same number of files in them.
I have managed to get this work for 1 file using
files1=($home/dir1/'*'-split.csv.'*')
grep -h '^[^\s]*' $files1 | xargs -I '{}' sed -i s'/userid/{}/' /home/dir2/*.py.*.py
But I don't know how to turn this into a loop so that the files from files1 are inserted into the files in files2.
As above, the sed statement looks to replace 'userid' in files2 which are located at /home/dir2/*.py.*.py with the contents of the file in files1 located at /home/dir1/*-split.csv.*.
All the files in files2 have 'userid' in them and this is the string to replace each time with the contents of a file from files1.
Does anyone have any ideas? Thanks!
Edit
Hi guys, thank you for your comments and pushing me for a better explanation!
Hopefully this sheds some more light on things... list of files like this...
ls /home/dir1/*-split.csv.*
just-users-split.csv.aa
just-users-split.csv.ab
just-users-split.csv.ac
just-users-split.csv.ad
Each file contains a single line of text e.g.
cat *.aa
"userPhD","userdegree","user123",
cat *.ab
"userxyz","userabc","user456"
In files2, I have a corresponding list of 4 files e.g.
ls /home/dir2/*.py.*.py
twud.py.1.py
twud.py.2.py
twud.py.3.py
twud.py.4.py
All of the *.py.*.py files are a copy of each other and contain a 91 line python script.
I then want to insert the contents of
just-users-split.csv.aa into twud.py.1.py
just-users-split.csv.ab into twud.py.2.py
just-users-split.csv.ac into twud.py.3.py
just-users-split.csv.ad into twud.py.4.py
The inserting can either be done at the top or bottom of the *.py file, or in an ideal world, the contents of just-users-split.csv.aa would be inserted on line 33 to replace the current string ids = "userid".
Finally, in this example there are 4 files to loop through but in other situations, it may be that there are 5, 10 or 20 pairs of files to loop through.
Does this make any more sense?