bash on davidchua https://dchua.com/tags/bash/ Recent content in bash on davidchua Hugo -- gohugo.io en-us Sun, 19 Sep 2021 07:44:01 +0000 Capturing Groups in Sed https://dchua.com/posts/2021-09-19-capturing-groups-in-sed/ Sun, 19 Sep 2021 07:44:01 +0000 https://dchua.com/posts/2021-09-19-capturing-groups-in-sed/ While migrating this blog from Jekyll to Hugo, I found I needed to replace all my old markdown posts which has my title params using single-quotes which Hugo does not appreciate, to double-quotes. For example, I have the following across multiple files (over 200+ files) --- title: 'abcdefg' tags: - new - stuff --- And I needed to replace title: 'abcdefgh' with title: "abcdefgh". To do that, I’m going to use sed because its going to be terribly painful to do this manually. Timestamp your bash output https://dchua.com/posts/2015-10-24-timestamp-your-bash-output/ Sat, 24 Oct 2015 00:00:00 +0000 https://dchua.com/posts/2015-10-24-timestamp-your-bash-output/ If you need to find out the time difference between bash outputs, you can use ts from the moreutils package. To get started, you’ll need to install moreutils. A simple apt-get install moreutils should do the trick. Then all you need to do is to pipe your output to ts Like: echo -e "test\ntest\ntest" | ts This will return a nice timestamp on each linebreak. You can even customize the timestamp like: Run a webrick server to serve static html content in a folder https://dchua.com/posts/2014-09-19-run-a-webrick-server-to-serve-static-html-content-in-a-folder/ Fri, 19 Sep 2014 00:00:00 +0000 https://dchua.com/posts/2014-09-19-run-a-webrick-server-to-serve-static-html-content-in-a-folder/ Need a quick way to serve html files? Want to quickly share your static website to the rest of the world, this snippet might help: /directory/to/static/html$ ruby -run -e httpd . -p 9000 Reference: Tenderlove’s Twitter