Posts

Showing posts from November, 2021

How To - Shell Scripting - Bash - Basics - 2 - AWK command usage

How To - Shell Scripting - Bash - Basics - 2 - AWK command usage Hello Everyone, In this post I will share what I have learned on awk . A little bit introuduction of awk AWK is a domain-specific language designed for text processing and typically used as a data extraction and reporting tool. Like sed and grep, it is a filter, and is a standard feature of most Unix-like operating systems awk has more variety of usages and all that information is well documented at https://www.gnu.org/software/gawk/manual/gawk.html All the code [more code in Gitlab repo than in blog, cause I am too lazy to reproduce my work :( ], along with sample files I am using in this blog post are commited to Github: https://github.com/rajagennu/awk_tutorial AWK IF-Else File: answers.txt a,1,1 b,3,4 c,5,2 d,6,1 e,3,3 f,3,7 awk -F ',' '{if( $2 == $3 ){print $1 "," $2 "," $3 } else {print "No Duplicates"}}' answers.txt output a,

How To - Shell Scripting - Bash - Basics - 1 - Functions

How To - Shell Scripting - Bash - Basics - 1 - Functions Hello Everyone, I will try publishing a series of articles on shell scripting. We are going to use bash which is default shell in almost all famous linux & unit operating systems. Functions The theory behind creating a function is simple, if you have a piece of code and you are going to use over and over, then instead of rewriting the code, you will make it as a function. Function Syntax: function function_name { # commands } In bash we have one more syntax for definiting functions. function_name ( ) { # commands } So lets get to the point, where functions are for better use. For example, lets say you are printing a format message for the commands you have executed and your code is like below uptime_output = $( uptime ) free_ram = $( free -m ) cpu_core = $( nproc ) echo "Command : uptime output $uptime_output " echo "Command : Free RAM $free_ram " echo &quo

How To: Logging with Javascript using Date class

Hello, If you are trying to print a neat date format in Javascript using Date() class, then you can use below snippet. Its a ES6 based function with template literals. const date = () => { const d = new Date(); return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}_${d.getHours()}-${d.getMinutes()}-${d.getSeconds()}_${d.getMilliseconds()} => `; };      If you are looking for ES5 syntax, you can use below one var getDate = function() { var d = new Date(); return d.getFullYear()+"-"+d.getMonth()+"-"+d.getDate()+"_"+d.getHours()+"-"+d.getMinutes()+"-"+d.getSeconds()+"_"+d.getMilliseconds()+" =>"; }; Hope it helps. Thank you.

How to resolve VERR_NEM_VM_CREATE_FAILED in Windows ?

How to resolve VERR_NEM_VM_CREATE_FAILED in Windows ? Hello Everyone, So I tried to install VirtuaBox VM in Windows 10 and I was getting VERR_NEM_VM_CREATE_FAILED error. After trying many solutions and searching a log in internet, Finally issue got resolved with below command. Open cmd prompt as Administrator. Shut down all programs. You will have to shut down, unplug, and restart your host. Ensure that none of these things are running: DeviceGuard CredentialGuard Windows Defender’s Core Isolation Find the Command Prompt icon, right click it and choose Run As Administrator. Enter this command: bcdedit /set hypervisorlaunchtype off Then run below command DISM /Online /Disable-Feature:Microsoft-Hyper-V Enter this command to shutdown your system shutdown -s -t 2 When the computer turns off, unplug it for 20 seconds. Then plug it in again and boot up Windows 10. After following these instructions, my issue got resoved and I am able to b

ServiceNow: How to get current scope name ?

Hello Everyone If you want to know what is your application scope name, then you can use below API gs.info ( gs.getCurrentScopeName() ); Hope it helps. Thank you

How to: Bash PID of last execute command

Hello Everyone In shell scripting if you want to get PID of last executed command, then you can use BASH `$!` meta variable. For example lets say if you have below command # nohup sha256sum 1g.bin & If you want to find that job PID which is running in the background, use below command # echo $! For Example [x:/tmp]# nohup sha256sum 1g.bin & [1] 14866 [x:/tmp]# nohup: ignoring input and appending output to `nohup.out' [x:/tmp]# echo $! 14866 [x:/tmp]# pgrep sha256sum 14866 Hope it helps. Thank you.