The solution is to use a raw triple-quoted string.
f = r"""awk -F"\t" '{print$5" "$6" "$7}' file.txt | sort | uniq -c"""
문제
I am attempting to feed a string to the terminal from python but I can't get my string formatted correctly.
c="awk -F\"\t\" '{print$5\" \"$6\" \"$7}' file.txt | sort | uniq -c"
when you look at this in the shell you get:
>>> f="awk -F\"\t\" '{print$5\" \"$6\" \"$7}' file.txt | sort | uniq -c"
>>> f
'awk -F"\t" \'{print$5" "$6" "$7}\' file.txt | sort | uniq -c'
Why are there \'s before the single quotes? How do I get rid of them? I have tried """string""" and '''string'''
In a previous program i had this:
>>> t="awk '{print $4}' file.txt | sort | uniq"
>>> t
"awk '{print $4}' file.txt | sort | uniq"
I'm not sure what the difference is
해결책
The solution is to use a raw triple-quoted string.
f = r"""awk -F"\t" '{print$5" "$6" "$7}' file.txt | sort | uniq -c"""