Friday, October 12, 2018

AWS S3 delete all unversioned buckets using AWS CLI

aws s3 ls | awk '{print $3}' | grep -v do-not-delete | xargs -L 1 -I {} aws s3 rb s3://'{}' --force

Wednesday, June 27, 2018

View a very long line in unix terminal using VIM editor

Steps to view a very long line in vim

  1. Open the file in vim
  2. Goto very long line
  3. write that line to temp file
  4. exit vim
  5. cat that temp file
Commands
  1. vim my_log_file.log
  2. :2345
  3. :2345w /tmp/very_long_line.txt
  4. :q!
  5. cat /tmp/very_long_line.txt

Tuesday, May 15, 2018

Directly open gz log files in vim

To open .gz which has log files directly in vim editor

create or update .vimrc file with below code
augroup gzip
 autocmd!
 autocmd BufReadPre,FileReadPre *.gz set bin
 autocmd BufReadPost,FileReadPost   *.gz '[,']!gunzip
 autocmd BufReadPost,FileReadPost   *.gz set nobin
 autocmd BufReadPost,FileReadPost   *.gz execute ":doautocmd BufReadPost " . expand("%:r")
 autocmd BufWritePost,FileWritePost *.gz !mv <afile> <afile>:r
 autocmd BufWritePost,FileWritePost *.gz !gzip <afile>:r
 autocmd FileAppendPre      *.gz !gunzip <afile>
 autocmd FileAppendPre      *.gz !mv <afile>:r <afile>
 autocmd FileAppendPost     *.gz !mv <afile> <afile>:r
 autocmd FileAppendPost     *.gz !gzip <afile>:r
augroup END
 vim apple.gz will open the log file directly in the editor

Reference : https://stackoverflow.com/questions/5396363/how-to-open-gzip-text-files-in-gvim-without-unzipping