LoginSignup
0
0

More than 3 years have passed since last update.

sedコマンドチートシート

Last updated at Posted at 2018-12-16

N行目だけ表示する

1行目だけ表示する
sed -n 1p < data/ladies_tokyo.csv

N行目だけ削除する

  • dコマンドを使う
1行目だけ削除する
sed '1d'

2行ずつ読み込んで1行で表示する

  • Nコマンド(入力の次の行をパターンスペースに読み込む)を使う
  • 「現在の行」と「次の行」をパターンスペースに読み込んでいる状態で、パターンスペースに対して改行を改行以外の文字に置換すると、2行が1行になる
$ printf 'aaa\nbbb\nccc\nddd\n' | sed 'N; s/\n/ /g'
aaa bbb
ccc ddd

from: http://blog.livedoor.jp/morituri/archives/52036613.html

yyyymmddHHMMSSyyyy-mm-dd HH:MM:SSに変換する

utconvというコマンドの出力がこれなので人間に見やすい形式に変換したい。

$ utconv -r 1574650550 | sed 's/^\([0-9]\{4\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)$/\1-\2-\3 \4:\5:\6/'
2019-11-25 11:55:50

改行で置換する

<RS> <US> などの不可視文字で置換してからtrで改行文字(LF)と入れ替える。

$ RS="$(printf '\036')"; (tr -d '\n' | tr -s ' ' | sed 's/\. /\.'${RS}'/g' | tr ${RS} '\n') <<'EOF'
Include the specified configuration file(s).  Multiple pathnames
             may be specified and each pathname may contain glob(7) wildcards
             and, for user configurations, shell-like `~' references to user
             home directories.  Files without absolute paths are assumed to be
             in ~/.ssh if included in a user configuration file or /etc/ssh if
             included from the system configuration file.  Include directive
             may appear inside a Match or Host block to perform conditional
             inclusion.
EOF
Include the specified configuration file(s).
Multiple pathnames may be specified and each pathname may contain glob(7) wildcards and, for user configurations, shell-like `~' references to user home directories.
Files without absolute paths are assumed to be in ~/.ssh if included in a user configuration file or /etc/ssh if included from the system configuration file.
Include directive may appear inside a Match or Host block to perform conditional inclusion.
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0