LoginSignup
1
0

More than 1 year has passed since last update.

役立ったターミナル操作〜備忘録〜 

Last updated at Posted at 2022-02-12

何をまとめてるの?

ターミナル上でのテキスト操作で役立ったものを備忘録としてまとめます。
随時更新していく予定です。

sedで複数単語置換(22/02/12更新)

やった事

テキスト中の複数の単語を対応する単語へ同時に変換します。オプション-fを用います。

目標: Windows is goodMac is godに変換 
方法:

#sed.txt
s/Windows/Mac/g
s/good/god/g

#以下コマンドで置換
echo "Windows is good" | sed -f sed.txt 

#出力
Mac is god

行列変換(22/02/18)

やった事

行列的に記述されたテキストファイルの、行と列を入れ替えます

目標:tateyoko.txtの行と列を入れ替えます。
方法:

#tateyoko.txt
1 2 3
4 5 6
7 8 9
#コマンド
cat tateyoko.txt | python -c "import sys; print('\n'.join(' '.join(c) for c in zip(*(l.split() for l in sys.stdin.readlines() if l.strip()))))"
#出力
1 4 7
2 5 8
3 6 9

複数ファイル移動orコピー(22/0727)

やった事

複数のファイルを一気に一つのディレクトリへ移動orコピーさせます

mv file1 file2 file3 DIRECTORY/
cp file1 file2 file3 DIRECTORY/
1
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
1
0