Data Science at the Command Line学习笔记(二)

1、vagrant建立简单httpserver方法:

1)映射端口

 修改Vagrantfile, 末尾添加本地端口和虚机端口的映射关系, 然后执行vagrant reload.  

   Vagrant::Config.run do |config|
        # Forward guest port 8000 to host port 8000
        config.vm.forward_port 8000, 8000
   end 

需新增端口映射,只需增加

config.vm.forward_port 80, 8080

2)启动HTTPServer

    通过python自带web服务器SimpleHTTPServer,在特定目录下(建立一个index.html)输入下面的命令来启动web服务器,提供一个文件浏览的web服务。

    $python -m SimpleHTTPServer 8000

    然后在浏览器输入http://localhost:8000

    就可以看到上述目录下的所有目录和文件了,-m用于指定端口。

2、强大的parallel

1)parallel用于并行执行命令,加快处理速度,但是每次都会提示版权信息,可以用--bibtex后输入will cite,去除版权提示。

$ parallel --bibtex

When using programs that use GNU Parallel to process data for publication please cite:

@article{Tange2011a,
title = {GNU Parallel - The Command-Line Power Tool},
author = {O. Tange},
address = {Frederiksberg, Denmark},
journal = {;login: The USENIX Magazine},
month = {Feb},
number = {1},
volume = {36},
url = {http://www.gnu.org/s/parallel},
year = {2011},
pages = {42-47}
}

(Feel free to use 
ocite{Tange2011a})

This helps funding further development.

Type: 'will cite' and press enter.
> will cite

Thank you for your support. It is much appreciated. The citation
notice is now silenced.

这样以后就不会每次命令提示版权信息。 

parallel命令的用法比较

$find data -name '*.txt' -exec echo "Processin {}" ;

$find data -name '*.txt' -print0 | parallel -0 echo "Processin {}"

如果采用exec参数的话,注意-exec 最后结尾为一个空格加“”加“;”,因为;可能在不同shell有不同解释,加上来转义,确保exec参数之后的命令能正确执行。

 3、神器jq来处理json

1)  jq .格式化显示json数据,瞬间觉得json数据可读了;

2)  curl -s "http://api.openweathermap.org/data/2.5/forecast?q=shanghai,cn&mode=json" | jq -c '.list[] | {temp: .main.temp,weather: .weather[].description,time: .dt_txt}'| json2csv -p -k temp,weather,time >forecast.csv

curl 中含有&注意一定要""包含起来;

jq -c 压缩显示,不分行显示,注意:[] .的使用与json文件中一致






原文地址:https://www.cnblogs.com/woodyle/p/4609190.html