Skip to content

Tag: awk

Increment variable when matched awk from tail

I’m monitoring from an actively written to file: My current solution is: However when attempting to do this with AWK I don’t get the output – the $ws_trans and $sc_trans remains 0 Attempting to do this to reduce load. I understand that AWK doesn’t deal with bash variables, and it can g…

Insert text if column contains a number

I have a tab-delim file that looks like this It should be three columns but some rows are missing the second column (bacterial taxonomy). For these rows I want to move the number to a third column and insert some text (such as Unclassified). I have been attempting to modify some commands I found online to ins…

How to do parsing of Elapsed time in seconds in linux

I want to do parsing of Elapsed time in seconds .Time formats given below: i’m getting values from systemctl status cassandra | awk ‘/(Active: active)/{print $9, $10,$11}’ Now storing it’s value in variable A,like now A has input as 3 day 18h or 3 day etc. More examples- A=3 day 18h or…

Print the two matched variables of awk in same line

This is the script which i wrote. The logs.txt consists of : In this the expected output is : But the output i am getting is : Can anyone rectify what is the error ? Answer I thinks this problem should be separated multiple problems. How do you think about below code? You can see what these code actually do

How to find which column has special characters in a file

I would like to find out which column has special characters in a file For example, I have the data below: Desired output: I want the record number along with the column numbers that have special characters. Answer You didn’t define special character. I will assume that you mean anything outside of the …

Convert column to matrix format using awk

I have a gridded data file in column format as: I would like to convert it to matrix format as: Where top 20.5 21.5 22.5 indicate y and side values indicate x and the inside values indicate the corresponding grid values. I found a similar question here Convert a 3 column file to matrix format but the script i…