タグ

linuxとshellに関するyotenaのブックマーク (5)

  • 置換・行や文字の削除などの文字列操作:sed:Technical tips:Media hub

    linuxでテキストファイルを編集するのを自動化したい場合が結構ある。たとえばApacheなどのプログラムをインストールするときに設定値を置換するなど。bashでこういうことをする場合はsedなどで置換を行うとよい。sedの簡単な使い方を説明します。 以下の例で頻繁的に使っている-i オプションは指定したファイルをそのまま上書きします。パイプでつないだり、リダイレクトしたりする場合は不要です。 空行を削除 sed -i '/^$/d' target.txt 文字列を削除 sed -i 's/文字列//g' target.txt 文字列を含む行を削除 sed -i '/文字列/d' target.txt 設定ファイルの特定の行を削除するときに使えます。 対象文字列を置換文字列に置換 sed -i 's/対象文字列/置換後文字列/g' target.txt 設定ファイルの値を変更したりコメント

  • Bash Shell Scripting - 10 Seconds Guide

    This Bash shell scripting guide is not a detailed study but a quick reference to the BASH syntax. So lets begin... Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable in MSDOS. HOME - Home directory of the user. MAIL - Contains the path to the location where mail addressed to the user is stored. IFS - Contains a string of characters whi

  • 10 Tools To Add Some Spice To Your UNIX/Linux Shell Scripts - nixCraft

    🐧 nixCraft → Linux → 10 Tools To Add Some Spice To Your UNIX/Linux Shell Scripts There are some misconceptions that shell scripts are only for a CLI environment. You can efficiently use various tools to write GUI and network (socket) scripts under KDE or Gnome desktops. Shell scripts can make use of some of the GUI widget (menus, warning boxes, progress bars, etc.). You can always control the fin

    10 Tools To Add Some Spice To Your UNIX/Linux Shell Scripts - nixCraft
  • What's "LANG=C" ?

    はてなブログ」に移行しました。 1日1更新……を目指せなくなってきてるブログ。自分の勉強のために作りました。継続は力なり。 今は主にUbuntuとAndroidネタが中心です。 コマンドを、日語環境でなく英語環境で実行したいとき、LANG=Cと付けて実行してやったりする。 $ dateと$ LANG=C dateのそれぞれの実行結果を見比べると一目瞭然。 しかし、このCってのがよくわからん。英語環境を表すのにはenというのも用意されていて、実際に$ LANG=en dateとやると、やはり英語で表示してくれる。 じゃあ、Cって何なのよ。と思い調べてみた。 それで見つけたのが、次のページのこの記述 http://mailman.linuxchix.org/pipermail/techtalk/2002-November/013691.html 'LANG=C' sets the loca

  • シェルスクリプト - Landscape

    とあるサーバのテストで大量のダミーメールを一気に送信する必要が出た。大量と言ってもたかだか千通程度なので、簡単にシェルスクリプトを書いて送信。 $ max=1024; date=`date`; for i in `seq 1 $max`; do echo $date |mail -s "Mail Test $i/$max $date" landscape@example.jp; done; 表題には "Test Mail 1/1024 Mon Apr 10 12:58:19 JST 2006" などという文字列が、文には日付だけがセットされる。Perl で書いても良かったけど、このマシンには SMTP 系のモジュール入れてたかどうかわからなかったのでシェルスクリプトにした。mail コマンドを使ってるので、ローカルで sendmail などの MTA が動いている必要がある。 ・・・あれ

  • 1