gringomike
Technical User
Hi all,
I've written the following (extremely untidy!) section of code that generates a csv file;
for line in `find /path1 -name "file1.txt" | sort `
do
echo $line >> ./list
done
sort ./list > ./list2
for line in `cat ./list2`
do
ls -1 $line | awk -F/ '{print $3}' >> /path/to/file/a.txt
cat $line >> /path/to/file/a.txt
# cat a.txt | sed -e 's/^some_text=//' -e 's/^more_text="//' -e 's/"//' -e '/^$/d' -e 's/^[ \]*//' -e '1d' -e '$d' > x.txt
cat a.txt | sed -e 's/^some_text=//' -e 's/^more_text="//' -e 's/"//' -e '/^$/d' -e 's/^[ \]*//' |awk -F/ -f search.awk > z.txt
done
The problem I have is that the script doesn't write on a new line of the file z.txt each time it cycles through this loop.
z.txt contains data like this;
text1,text2,text3,text4,text5,text6,text7,text8,text9,text10,text11,text12,text13,text14,text15,
I need it to look like this;
text1,text2,text3,text4,text5,text6,
text7,text8,text9,
text10,text11,text12,text13,text14,text15,
i.e - every time it cycles through the loop, I need the output to be written to a new line.
My search.awk file looks like this (thanks vgersh99!);
BEGIN {
FS="(\\|)|(/)"
OFS=","
}
{
for(i=1; i <= NF; i++)
if (match($i, /.*[^0-9].*/) && !match($i, /^ *$/))
printf("%s%s", $i, OFS)
}
I've tried inserting a printf "\n" in various places but have so far had no success.
If anybody has any ideas about how to get round this I would be extremely grateful!
Thanks
GM
I've written the following (extremely untidy!) section of code that generates a csv file;
for line in `find /path1 -name "file1.txt" | sort `
do
echo $line >> ./list
done
sort ./list > ./list2
for line in `cat ./list2`
do
ls -1 $line | awk -F/ '{print $3}' >> /path/to/file/a.txt
cat $line >> /path/to/file/a.txt
# cat a.txt | sed -e 's/^some_text=//' -e 's/^more_text="//' -e 's/"//' -e '/^$/d' -e 's/^[ \]*//' -e '1d' -e '$d' > x.txt
cat a.txt | sed -e 's/^some_text=//' -e 's/^more_text="//' -e 's/"//' -e '/^$/d' -e 's/^[ \]*//' |awk -F/ -f search.awk > z.txt
done
The problem I have is that the script doesn't write on a new line of the file z.txt each time it cycles through this loop.
z.txt contains data like this;
text1,text2,text3,text4,text5,text6,text7,text8,text9,text10,text11,text12,text13,text14,text15,
I need it to look like this;
text1,text2,text3,text4,text5,text6,
text7,text8,text9,
text10,text11,text12,text13,text14,text15,
i.e - every time it cycles through the loop, I need the output to be written to a new line.
My search.awk file looks like this (thanks vgersh99!);
BEGIN {
FS="(\\|)|(/)"
OFS=","
}
{
for(i=1; i <= NF; i++)
if (match($i, /.*[^0-9].*/) && !match($i, /^ *$/))
printf("%s%s", $i, OFS)
}
I've tried inserting a printf "\n" in various places but have so far had no success.
If anybody has any ideas about how to get round this I would be extremely grateful!
Thanks
GM