The code is like this. > cmd = "grep -c pattern " + 'filelist3' + " > " + 'grepdata' > os.system(cmd) Move pattern outside the quotes: cmd = "grep -c " + pattern + " " + filelist3 + " > " + 'grepdata' I'm assuming filelist3 is also a variable? Alan G