I have at least 40 files (20 in xml. format and 20 in safe. format).
As example some of this:
iw1-20150612.SAFE.safe
iw2-20150714.SAFE.safe
iw1-20150612.xml
iw2-20150714.xml
I want to put this file names in a txt file in a certain place of text via terminal in Linux (or text is added during this process)
The text can be any as example:
anytext iw1-20150612.SAFE.safe
anytext2 iw1-20150612.xml anytext2 iw1-20150612.xml
anytext Iw2-20150714.SAFE.safe
anytext2 iw2-20150714.xml anytext2 iw2-20150714.xml
Example that I need here:
awk 'NR>1 {print $0}' < ../og/iw1-20150612.SAFE.safe > tmp_file
cat ../og/iw1-20150612.xml tmp_file ../og/m.xml > ./iw1-20150612.xml
awk 'NR>1 {print $0}' < ../og/iw2-20150714.SAFE.safe > tmp_file
cat ../og/iw2-20150714.xml tmp_file ../og/m.xml > ./iw2-20150714.xml
#and etc
It's also important to keep sorting by file name as in the folder. My attempt:
find /any/directory/ -type f -printf "%f\n" >> data.txt
But I don't know how to 'choose a place' to insert text.
You can use a simple bash for loop to loop over the filenames. As long as each
safefile has a correspondingxmlfile, you cansafefiles,xmlfilename and the texts from therescript.sh
Set
OUTFILEas required, uncomment thermif required.Update using awk
If you have many files and the bash for loop is to slow due to frequent writes to
$OUTFILE, here is a more shell-style version of the same idea:SAVE.safefilenames into awk,$1is the basename,$0the original filename)and create the desired text with
printf: