Awk print with pipes not working iPython in Jupyte

2019-05-26 00:58发布

问题:

So the command below does not give me any output in Jupyter Notebook with iPython:

IP = '62.172.72.131'
!cat hits.csv | grep {IP} | awk '{print $1}'

I have tried both double and single "$" sign and none of them works. If I only use one pipe in the command, it works fine. For example:

IP = '62.172.72.131'
!cat hits.csv | grep {IP}
!cat hits.csv | awk '{print $1}'

Anyone know why this is happening? Thanks!

回答1:

I think I figured this out. The "$" and "{" and "}" are all special characters in iPython, so I have to escape them by doubling them.

IP = '62.172.72.131'
!cat hits.csv | grep {IP} | awk '{{print $$1}}'