Skip to main content

Posts

Use vi editor to insert newline char in replace

In vi to insert a newline character in a search and replace, do the following  :%s/look_for/replace_with^M/g  The command above will replace all instances of “look_for” with  “replace_with\n” (with \n meaning newline)  Note: To get the “^M”, enter the key combination “ctl-V” then after that (release all keys) press the “enter” key.
Recent posts

Find : Multiple files with different strings

Use find command for multiple search string? Yes, we can. find . -type f \( -name "*.xvg" -o -name "*.log" \) We must not forget to have space before -name  in both the above occurrences. Enable Ginger Cannot connect to Ginger Check your internet connection or reload the browser Disable in this text field Edit Edit in Ginger Edit in Ginger ×

Clear the VI highlighting

Not any thing against other editors, VI is my fav. I often use it's in-built search feature to look out for words/phrases. I often had wondered, how can the yellow highlighting be turned-off. One way to do is simply type: :noh

tail n lines for all xvg files

During our day-to-day work, we end up all files with same extension. So, if we want to output the last few lines of similar type of files, we can follow the following approach. for xvg in *.xvg; do echo $xvg;cat $xvg|tail -2 $xvg; done By default,  tail outputs last 10 lines, so we cannot use: tail *.xvg If we want the look at the 2 lines instead of 10, we can use the above one-liners.