Skip to content

Tag: awk

Organize file by Linux

I want to thank the great help and support. Well, I have the following file: and I need that file be this way: Please, someone can help me? Thank you very much Answer awk to the rescue!

Select lines by condition and count with one line command

I need help with analyze nginx logs. Sample of log: Is it possible to select with count all uniq ip addresses which contain per_page parameter and this parameter equal or greater than 100? So, the output can be in any format: Is it possible to get with one command? Answer This is absolutely basic awk – …

Inserting text in a ‘find’ command search

I have a find string that finds all the instances of a particular filename in a path, like so: I need to return the result with ‘FINENAME=’ prepended on each line. Having a hard time figuring the best way. Answer Note that if you have a directory named /opt/logs (and you’re not trying to loo…

Convert number from text file

I have a file: id name date 1 paul 23.07 2 john 43.54 3 marie 23.4 4 alan 32.54 5 patrick 32.1 I want to print names that start with “p” and have an odd numbered id My command: grep “^p” filename | cut -d ‘ ‘ -f 2 | …. result: paul patrick Answer Awk can do it all:

AWK script automatically removing leading 0s from String

I have a file BLACK.FUL.eg2: I’ve written this AWK script: which gives me an output of: with one problem: the leading 0s of strings in field1, are automatically getting removed due to a numeric operation on them. So my actual expected output is: For that I’m trying the below updated AWK script: Bu…

substitute consecutive tabs for “tNAt”

Have a badly formatted tsv file with empty fields all over the place. I wish to fill these empty spaces with “NA” on linux. I tried awk ‘{gsub(“tt”,”tNAt”); print$0)’ but that only substitutes one empty space to NA instance. Chaining the command awk ‘{gsub…

How can I sum only a column range using awk?

I have this file : And I’am trying to sum the values in the forth column based in a range for example each 1 million using the second column as reference. I’am using this code karakfa taught me: it outputs me this : but it sums all column in the file, not only the range I’ve created. if I us…