Mac下&&Shell里各种技巧

xargs和sed联合处理的例子。这个貌似和linux下也不一样。

ls | xargs -I {} sed -i '' 's/balabalabala/\*/g' {}


今天又学到个sed -i 在mac里的in-place替换,跟linux语法不大一样。。

下面是截取关键部分,详见https://mpdaugherty.wordpress.com/2010/05/27/difference-with-sed-in-place-editing-on-mac-os-x-vs-linux/

sed in-place editing (-i) difference on Mac OS X: “undefined label” errors

sed -i '.bak' 's/before/after/' test.txt

leaves you with two files, ‘test.txt‘ and ‘test.txt.bak‘, where ‘test.txt.bak‘ is the original version.  Unlike Ubuntu and other linux versions, on OS X, this extension parameter is required.  If you really know what you’re doing and don’t want a backup made, you need to provide an empty string ”.

The correct way to run this command on OSX is

sed-i '' 's/before/after/'test.txt


pip3 install tensorflow==2.0.0-beta1 第一次知道可以这样指定版本。哈哈。

while IFS=$'\t' read -r bugId content

The -r tells read that \ isn't special in the input data; 

https://stackoverflow.com/questions/9736202/read-tab-separated-file-line-into-array :

Actually -r added by @gniourf_gniourf avoid the expansion of backslashed characters, if doing so %bcould be substituted by %s in the printf format strings cause backslashed scaped characters will be represented as literals. So, use it or not depending on what you really want to do. –slylittl3 Feb 19 '15 at 2:05

---------

The new line character with the echo command is "\n". Taking the following example:

echo -e "This is line 1\nThis is line 2"

Would result in the output

This is line 1This is line 2

The "-e" parameter is important here.

printf "hello\nworld\thaha\n" 可以自动将\n和\t换成相应的换行和tab输出,amazing!

tail -n +2 myfile.txt 从第二行开始读直至末尾

------------------------------------

每次Mac用brew安装时都要update,可烦,后面发现可以不让其update:

HOMEBREW_NO_AUTO_UPDATE=1 brew install xxx

------------------------------------

mac截图各种工具, 具体见下文链接:

http://jingyan.baidu.com/article/76a7e409b50525fc3b6e15ac.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在此特此声明:一下所有链接均来自互联网,在此记录下我的查阅学习历程,感谢各位原创作者的无私奉献 ! 技术一点一点积...
    远航的移动开发历程阅读 11,239评论 12 197
  • 很多人会和许多人说声晚安! 但是又有多少人会和自己说晚安! 期待着有个人陪伴,有人亲切的说晚安! 但人生长路陪着自...
    婷freedom阅读 379评论 0 0
  • 最近情绪不太对,做任何事似乎都提不起精神,很莫名。 想找一个地方,敲下些许心绪,也许有一天你会看见它们,找到我。 ...
    Doris_Lin阅读 347评论 0 1
  • 时间总是过后,才显的飞快。 转眼已和《通往财富自由之路》共同走过一年,专栏第一季也落下帷幕。 这一年在学习...
    东涂西抹阅读 331评论 0 2
  • 一直以来,都把爱情和婚姻列入神坛,觉得收获好的爱情,人生就会发生质的蜕变。但最近,在微博上看到的大大小小的事件,都...
    lynnli_j阅读 239评论 0 0