LoginSignup
4
4

More than 5 years have passed since last update.

Bashメモ

Last updated at Posted at 2014-03-14

ファイルを1行ずつ読む

while の標準入力に渡してあげる。

例1)

while read line; do
  echo "LINE: $line"
done < {ファイル名}

例2)

cat {ファイル名} | while read line; do
  echo "LINE: $line"
done

標準出力と標準エラー出力をファイルに追記

exec >> ./log.txt  2>&1

ファイルがシンボリックリンクか判断する

if [ -L hoge.txt ]; then
  echo "hoge.txt is symbolic link"
fi

なお、ディレクトリでも同様に判定できるけど、最後に / つけると常にfalseになるみたい。

if [ -L /var/www ]; then
  echo "/var/www is symbolic link"
fi
# => OK

if [ -L /var/www/ ]; then
  echo "/var/www/ is symbolic link"
fi
# => NG

参考: man test

列を縦にする

$ cat hoge.csv | head -n 1 | perl -pe 's/,/\n/g'

1行目を取り除く(ヘッダ行など)

$ tail hoge.csv -n +2 > hoge-2.csv
4
4
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
4
4