Tag Archives: awk

AWK: convert into lower or upper cases

In order to convert a bash variable to lower case with awk, just use this command: a="UPPER CASE" echo "$a" | awk ‘{print tolower($0)}’a="UPPER CASE" echo "$a" | awk ‘{print tolower($0)}’ If you want to convert the content of a … Continue reading

Posted in Linux | Tagged , | Leave a comment

swapping two columns with awk keeping tabulation

Assuming you have a data file with N columns and you want to swap the first and second one, just type: awk -F $’\t’ ‘ { t = $1; $1 = $2; $2 = t; print; } ‘ OFS=$’\t’ input_fileawk … Continue reading

Posted in Linux | Tagged | Leave a comment

How to calculate mean in AWK

Another trick with awk to compute mean of a column. Imagine that you have a file with many lines and you want to compute the mean of the fourth item on each line. E.g: Lowest value found .2 Lowest value … Continue reading

Posted in Linux | Tagged | Leave a comment

How to resize images with awk and convert

If photos in a directory are too large, you may want to use a script to automatically convert all the files into another format. AWK and convert tools can help you. The following command should convert all the files with … Continue reading

Posted in Linux, photos | Tagged , | Leave a comment

Combine AWK and SED to create symbolic links

The unix tools AWK and SED are very powerful tools to manipulate files and perform text processing tasks. It’s true that the syntax is not always very intuitive but it can help you in performing task in a single line. … Continue reading

Posted in Linux | Tagged , | 1 Comment

AWK: the substr command to select a substring

Under Linux, the awk command has quite a few useful functions. One of them, which is called substr, can be used to select a substring from the input. Here is its syntax: substr(s, a, b) : it returns b number … Continue reading

Posted in Linux | Tagged | 12 Comments

Awk: how to convert PNG files into PDF

Here is a method to convert a bunch of PNG files into another format (here PDF). This method works under linux and uses both awk and convert commands (the conversion is made with the convert command). The following script generates … Continue reading

Posted in Linux, Uncategorized | Tagged | Leave a comment