cool sed/grep magic to convert output to csv format

2019-03-11 1 min read bash Learning
I generallly keep doing this a lot, so thought will share with you. Lets assume we are capturing free ouput every min/hour/or whatever. The output looks like this: Time: Mon Jan 21 23:59:10 AEDT 2019 ——————- total used free shared buff/cache available Mem: 32014 8656 1735 1697 21621 21308 Swap: 51195 75 51120 then we can use some grep and sed to convert this to something like this: Mon Jan 21 23:59:10 AEDT 2019,32014,8656,1735,1697,21621,21308 Continue reading

Get to your ebooks quickly

2018-11-12 2 min read Linux Uncategorized
So this is going to be a little longer post than usual. To begin with, here is screenshot of how it would look like finally: We are using “rofi” here to show the menu. So, lets first install that cat <<EOF >/etc/yum.repos.d/_copr_yaroslav-i3desktop.repo [yaroslav-i3desktop] name=Copr repo for i3desktop owned by yaroslav baseurl=https://copr-be.cloud.fedoraproject.org/results/yaroslav/i3desktop/fedora-$releasever-$basearch/ type=rpm-md skip_if_unavailable=True gpgcheck=1 gpgkey=https://copr-be.cloud.fedoraproject.org/results/yaroslav/i3desktop/pubkey.gpg repo_gpgcheck=0 enabled=1 EOF yum install rofi Once that is done, we will create a small script to look for all our pdf files and display that in the menu, like above. Continue reading

Generate random string for various use case

2016-08-08 1 min read bash
Some times I need random string, for example to use as email seperator or to use in some API. One way is to use tools like /dev/[u]random or od and other such. But they seem cubersome after I figured this out. openssl rand <length> openssl rand 10 This alone without some parameters is not interesting thoug. You can use ‘-base64’ or ‘-hex’ to select the encoding. So if you execute the above you will get something like this Continue reading

image ordering by Original Date Time using bash script

2016-01-05 1 min read bash
Here is the script: #!/bin/bash - #=============================================================================== # # FILE: imgOrg.sh # # USAGE: ./imgOrg.sh # # DESCRIPTION: # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Amit Agarwal (aka) # REVISION: --- #=============================================================================== for i in * do if [[ $(file $i) == *image* ]] then echo "Image file is :: $i" dir=$( exiftool -s -DateTimeOriginal $i | awk -F':' '{print $2"/"$3}') mkdir -p $dir cp $i $dir/ else echo " Continue reading

Get count of lines in scripts (shell)

2015-10-15 1 min read bash
If you have tried to get the count of lines in file, the you would know about “nl” or “wc -l”. But as you are aware these give you number of lines with other details as well and you need to post process the number to make sure that you have only number and nothing else. In such cases, it is useful to use the count feature of grep and here is a shorthand to get the count of lines in any shell script: Continue reading

The power of find command in Linux – advanced.

2010-05-24 2 min read Linux
Generally whoever uses Linux, would know about the find command. Find the man page <a href="http://amit.themafia.info/phpMan.php?parameter=find&mode=man" target="_blank">here. There are also lots of blogs, tutorials and other articles on find command on the web, so why write another one. Because it&#8217;s worth every word spent on it 🙂 find is a very powerful command, let&#8217;s see how (options for find command from man page and usage): –depth — Process each directory&#8217;s contents before the directory itself. Continue reading
Older posts Newer posts