Awk is a useful language for many command line tasks. Often awk is used on the command line on its own or with strings piped to it, but it is possible to turn that awk code into an executable script. Consider the following script. This file contains awk code with a shebang of awk -f. The -f is …
Start reading Executable awk scripts in LinuxBlog
In awk, fields are accessed by number; $1 for the first field, $2 for the second, etc. But sometimes the field number you want to access is not known until run time. In these cases, you can access the field using the $(<index>) syntax. The constant NF contains the number of fields available. For example, you can print all fields with their field …
Start reading Accessing fields by index in AwkEver wanted to have a real-time clock on your linux terminal? We can create one with a single line of bash, like so: Let’s look at how this works: date is a common unix tool used to print the current date and time. The $(…) means that the date command is run, and the output is placed here instead. For …
Start reading Linux Terminal ClockThere are a number of ways to read keyboard input with python. One easy option is to use the curses library, using the getch() method, as shown below: The program above initialises the curses library, then sits in an infinite loop, printing a message whenever any keyboard buttons are pressed. Use ctrl-c to interrupt the loop and clean up curses before exiting gracefully. Note that …
Start reading Reading keyboard input with PythonIf you have a filename or list of filenames, you may want to strip the extension. There are a few ways of “detecting” which part of the filename is the extension, but may not work if your file has multiple extensions (e.g. .tar.gz), contains spaces or periods, or meets other weird criteria. If you know …
Start reading Removing a known extension from a filenameTips for research scholars – manuscript preparation tips IMRaD Introduction Methods Results Discussion Download Presentation
Start reading Research Document TipsIf you’ve got a string of items in bash which are delimited by a common character (comma, space, tab, etc) you can split that into an array quite easily. Simply (re)define the IFS variable to the delimiter character and assign the values to a new variable using the array=($<string_var>) syntax. The new variable will now be an array of …
Start reading Convert a delimited string into an array in BashSo you’ve got a USB drive, and you need to reformat it. You can do this all quite easily on the command line using the fdisk utility. First, get the device location. This will be something like /dev/sdd. You want the location of the device, not a partition on the device ie: /dev/sdd instead of /dev/sdd1. The instructions below work for …
Start reading Formatting a usb drive in linuxSometimes in a terminal you want to strip out the first line of output from a command. For example, you may want to generate a list of users which have tasks running using the ps command. This command puts a header at the top of the output. You can remove this header by piping the output to sed …
Start reading Ignoring the first line of output in a unix terminalEver jumped onto an Ubuntu server somewhere without knowing which operating system version it’s running? You can find this out with one simple command: This will provide output like:
Start reading Checking the Ubuntu version number