Deleted articles cannot be recovered. Draft of this article would be also deleted. Are you sure you want to delete this article?
Skip to the content. Bash-Oneliner I am glad that you are here! I was working on bioinformatics a few years ago and was amazed by those single-word bash commands which are much faster than my dull scripts, time saved through learning command-line shortcuts and scripting. Recent years I am working on cloud computing and I keep recording those useful commands here. Not all of them is oneliner, but i
ã¯ããã« ã³ãã³ãããã¤ãã§ã¤ãªããæãåã³ãã³ãã®éã«ã¯ããã¤ãã®ãããã¡ãåå¨ãã¾ãããã®ãããã¡ã«ã¤ãã¦ã¡ããã¨æèãã¦ããã§ããããï¼ ãããã¡ã®åå¨ã«ãã£ã¦åã³ãã³ãã®å®è¡ã«ã¯åããã¥ããå¤åãããã¾ãããã®ãããã¡ãç¥ããªãã¨ç½ ã«ããã£ã¦ãã¾ãã»ã»ã»ããããã¾ããã ããã»ã¹éã®ãã¤ãéä¿¡ã®ãããã¡ ã¾ãããã»ã¹éã®ãã¤ãéä¿¡ã«åå¨ãã¦ãããããã¡ã§ããå¤ãã®ã³ãã³ãã¯è¡åä½ã§ãã¼ã¿ãå¦çãã¾ãããä¸è¬çã«ãã¤ãã§ã¤ãªããåã³ãã³ãã¯ããããå¦çé度ãç°ãªãã¾ããå¦çãããã«çµããã³ãã³ããããã°æéããããã³ãã³ããããã¾ããåã³ãã³ãã¯ä¸¦åã§åä½å¯è½ã§ããå¿ ããã並åã§åä½ããããã§ã¯ããã¾ããã ä¸è¬è«ã¨ãã¦ãã¤ãã©ã¤ã³å ¨ä½ã®å¦çã«ãããå®æéã¯ãã¤ãã§ã¤ãªãã£ãã³ãã³ãã®ä¸ã§ä¸çªé ãã³ãã³ãã«è¶³ãå¼ã£å¼µããã¾ããããã並åã§åä½å¯è½ã¨è¨ã£ã¦ããã¼ã¿ãå°çããªããã°å¦çã
ããã¯ã©ã®ã³ã³ãã¥ã¼ãã£ã³ã°APIãbashã¹ã¯ãªããã§ãªã¯ã¨ã¹ãããããã® ã¹ã¯ãªãããæ¸ãã¾ããã params ãã©ã¡ã¼ã¿ã¼ãå¤æ´ãããã¨ã§ãä»»æã®APIããªã¯ã¨ã¹ãã§ãã¾ãã #!/bin/sh urlencode() { # https://qiita.com/ik-fib/items/cc983ca34600c2d633d5 echo "$1" | nkf -WwMQ | sed 's/=$//g' | tr = % | tr -d '\n' } HOST="jp-east-1.computing.api.nifcloud.com" ACCESS_KEY="<YOUR ACCESS KEY>" SECRET_KEY="<YOUR SECRET KEY>" TIMESTAMP="`date -u +'%FT%T.%2NZ' | sed -e 's/:/%3A/g'`" decla
ã¯ããã« ããæååã®ç½®æ㧠sed ã³ãã³ã使ãã®ç¦æ¢ãã¦è¯ãããããªãã§ãããï¼ è¨ãããã ã¨ããã£ã¦ããã¦è¨ã£ã¦ãã¾ããã æªãæ¸ãæ¹ï¼å¤é¨ã³ãã³ãã«é ¼ãæ¹æ³ï¼ # å¤æ° line ã«å ¥ã£ã¦ãæååã echo ã³ãã³ãã§åºåã㦠sed ã³ãã³ãã«æ¸¡ãã # sed ã® s ã³ãã³ã㧠"from" ã "to" ã«ç½®æãã¦åºåãããã®ã ret å¤æ°ã§åãåã ret=$(echo "$line" | sed "s/from/to/")
docker ã§ç°å¢ãä½ã£ã¦ã㦠docker compose build æã«è¨å®ãã¡ã¤ã«ã«ç°å¢å¤æ°ããåå¾ããå¤ãèªåã§è¨å®ãããã£ãããã¡ã¤ã«ã®å¤æ´ã¯ sed ã³ãã³ãã使ãã°è¯ãããã ã£ãã®ã§ç½®æã®æ£è¦è¡¨ç¾ã«ç°å¢å¤æ°ãå±éãã¦ç½®æã§ããã°è¯ãããã§ãã å¤æ°ã使ãå ´åã¯æ£è¦è¡¨ç¾ã " (ããã«ã³ã¼ãã¼ã·ã§ã³) ã§å²ãå¿ è¦ããã " (ããã«ã³ã¼ãã¼ã·ã§ã³) ã¯å¤æ°å±éãããããã' (ã·ã³ã°ã«ã³ã¼ãã¼ã·ã§ã³) ã ã¨å¤æ°åãã®ãã®ãæ£è¦è¡¨ç¾ã«åãè¾¼ã¾ãããã¾ãã $ THEME_NAME=soleil $ echo '/path/to/theme/' | sed -e "s/\/path\/to\/theme\//\/path\/to\/$THEME_NAME\//g" /path/to/soleil/ # ã·ã³ã°ã«ã³ã¼ãã¼ã·ã§ã³ã ã¨å¤æ°åã®ã¾ã¾ç½®æããã¦ãã¾ã $ echo '/p
grep ã§ã¯ å¾æ¹åç §ãã§ããªãã®ã§ã代æ¿æ¡ãèãããã¨ã«ãªãã æ¹æ³ï¼åºæ¬çãªæ¹æ³ -o ãããããç®æã ããåãåºã -o ã使ã£ã¦ããããããç®æã ããåãåºãã cat out.txt | \grep -Po 'Abc.*Xyz' æ¹æ³ï¼ å èªã¿ï¼ãã¨ãã¿ å èªã¿ã»å¾ãèªã¿ã«ãããããç®æã ããåãåºã -o ãçµã¿åãããã cat out.txt | \grep -Po '(?<=Abc).*(?=Xyz)' æ¹æ³ï¼ perl ã ruby ãªã©ã¯ã³ã©ã¤ãã¼ã使ã ãã¯ããgrep ã§ã¯ãªããã代æ¿æ¡ã¨ãã¦ã¯è¡ãã cat out.txt | ruby -pe 'sub(/^Abc(.*)Xyz/, "\\1")' æ¹æ³ï¼ sed ã§ç½®æãã ãã¯ããgrep ã§ã¯ãªããã代æ¿æ¡ã¨ãã¦ã¯è¡ããããsedã¯æ軽ã«ä½¿ããã cat out.txt | sed -nr 's/Abc
Linux(shellã³ãã³ã) ãã¡ã¤ã«æ¤ç´¢ dir/ é ä¸ã®.py ã¾ã㯠.ipynb ãã¡ã¤ã«ã§ hogehoge ãå«ããã®ãæ¤ç´¢ããã grep -r --include='*.py' --include='*.ipynb' "hogehoge" dir/ dir/ é ä¸ã®ç¹å®ã®æååãå«ããã¡ã¤ã«ãä¸æ¬ã§ç½®æããã ä¾ãã°ã calender ã®ã¿ã¤ããä¸æ¬ã§ä¿®æ£ãããå ´å find dir/* \( -name "*.py" -o -name "*.ipynb" \) | xargs sed -e 's/calender/calendar/g' -i mac OS ã®å ´å, POSIX sed ãæ¨æºã§å ¥ã£ã¦ããã®ã§ä¸æ¸ããã¦ãã¾ã£ã¦ããå®è¡ããã¨ãã brew install gnu-sed --with-default-names git è¤æ°ã«åãããã³ããããã¾ã¨ã
ã¯ããã« CSV ã®ããã«ã«ã³ãåºåãã®æååãããããã®ãã£ã¼ã«ãã«åå²ããã«ã¯ã©ããããï¼ã¨ãããã¿ã§ããããè¦ããã¿ãªã®ã§ãããè¯ãã¨ã¯è¨ããªãã³ã¼ããå¤ãã®ã§ã¾ã¨ãããã¨æãã¾ãã ãªãä¾ã¨ã㦠CSV ãæ±ã£ã¦ãã¾ããã主é¡ã¯æååã®åå² (split) ã¨çµå (join) ãªã®ã§ãããã«ã¯ã©ã¼ãã§ããããã¨ã§ã«ã³ããæ¹è¡ãå ¥ãããããªã©ã¨ããæ¬æ°ã® CSV 対å¿ã¯ãã¾ãããä»æ§ãè¤éãªã®ã§ãã®ãããªãã¡ã¤ã«ãæ±ãå ´åã¯å¥ã®è¨èªã®ããç¥ãããã©ã¤ãã©ãªã使ããã¨ããããããã¾ãããã®è¨äºã§æ±ã CSV ã¨ã¯åãã£ã¼ã«ããã«ã³ãã§åºåããã¦ããã¨ããã ãã®ãã®ã§ãã åæ ä¸è¡ã®ãã¼ã¿ã¯åå²ãã¦ä½ç½®ãã©ã¡ã¼ã¿ã¼ã«å ¥ãã ä¸è¡ã®æååãåå²ããçµæã¯ãä½ç½®ãã©ã¡ã¼ã¿ ($1, $2, $3, ...) ã«ä»£å ¥ããã®ãããããã§ããä½ç½®ãã©ã¡ã¼ã¿ã¯ POSIX æºæ ï¼ã¤ã¾ã bash
macOSæ¨æºæ·»ä» sed ã³ãã³ãã¯GNUæ¡å¼µé対å¿ã®ãããä¸è¨ã®ãããªã¯ã³ã©ã¤ãã¼ãæå¾ éãåä½ããªãã
ULAã®Prefixãçæãããªã openssl rand -hex 5 | sed -r 's|^(.{2})(.{4})(.{4})|fd\1:\2:\3::/48|' ãã¼ã«ã«ã¢ãã¬ã¹ã®ãã¬ãã£ãã¯ã¹ã®å ´åã¯ã prefix ã«16ã®ãããã¯ã¼ã¯ã»ã¢ãã¬ã¹ãä»ãããã¾ã¨ãã¦ã©ã³ãã çæããã¨ã openssl rand -hex 7 | sed -r 's|^(.{2})(.{4})(.{4})(.{4})|fd\1:\2:\3:\4::/64|' å®è¡ä¾ root@router01:~# openssl rand -hex 5 | sed -r 's|^(.{2})(.{4})(.{4})|fd\1:\2:\3::/48|' fd8b:9230:0268::/48 root@router01:~# openssl rand -hex 7 | sed -r 's|^(.{2})(.
sed -e 's/[[:cntrl:]]/\"[[:cntrl:]]\"/g' tes.tsv >> tes_t.tsv åãâ¦ã OS X 㯠¥t ã /t, \t ã§ã¯ããã [[:cntrl:]] ã§ã¿ãã表ç¾ã§ãã模æ§ã ãã ãããã¯POSIXæåã¯ã©ã¹ã®ãã¡ã®ãå¶å¾¡æåãã¨å¼ã°ããç¯å²ã§ãã¤ã¾ãCRã¨ãã«ãããããã¡ããâ¦ã ASCIIã³ã¼ãã® 0x00-1F, 0x7Fã§ããã ãããæå¹ã«ä½¿ããã®ããç¶æ³éå®ã§ããã ãã以å¤ã¯é½åº¦ãTerminal.appä¸ã§ ãCtrl+v -> Tabã ã¨æã¤ãããªãããã§ããã ã¾ããä¸åº¦ããã¹ããã¡ã¤ã«ã«åºãã¦ããã®ãªã
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}