Can anyone here with batch code experience help me come up with a code for the following psuedo code?

Code:
cmd = 'echo hi'

output = exec(cmd) #save the output of the command to the var

outputArr = output.breakAt('\n') # break the string into array of strings at new line

for (s in outputArr) #iterate through the array
{
   if (s.contains('x') || s.contains('y'))
      print (s.substring(i,end)) #print only a substring of the string
}
thanks