Understanding Awk and Cat

Hi Guys,

I was recently come across some code to hopefully learn a little bit about putting Shell commands into PHP application to run on a Linux server. However, I don't understand the command AT ALL... and was wondering if anyone can interpret it:

cat userIDs.dat | awk '{s=s+1; if (s==$end) print $0; if (s > $start && s < $end) printf \"%s,\", $0}' > path/to/file/to/store/in/IDS.file

It doesn't seem to do anything, but I may have put an error in there, when making it applicable to my directories etc. I have no clue!

Any light you guys can shed on this would be great!

Thank you,
Jordan

awk won't understand the shell variables.
you have to tell awk that those are shell variables.

so in your case "$end", "$start" etc are not being replaced by the actual values.

user double quotes or -v flag.

awk -v START="$start" -v END="$end" '{s=s+1; if (s==END) print $0; if (s > START && s < END) printf \"%s,\", $0}' > path/to/file/to/store/in/IDS.file

if you are facing problem related to your requirement, then please post your sample "IDS.file" and require output ( conditions).