Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Awk print with pipes not working iPython in Jupyter Notebook

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!

like image 907
JACK ZHANG Avatar asked Oct 21 '25 06:10

JACK ZHANG


1 Answers

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}}'
like image 81
JACK ZHANG Avatar answered Oct 24 '25 13:10

JACK ZHANG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!