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!
Tag: awk
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…
Comparing two files and updating second file using bash and awk and sorting the second file
I have two files with two colums in each file that I want to compare the 1st column of both files. If the value of the 1st column in the first file does not exist in the second file, I then want to append to the second file the value in the 1st column of the first file, eg firstFile.log
Select first match between two patterns.Restart search if a 3rd pattern is found using sed/awk/grep
I am struggling with the following task(I’ve been searching for answer for a while). The search is for text between START_PATTERN and END_PATTERN1 Having a file structured like this: The task would be to restart search if END_PATTERN2 is found. Thus the command output should be: Thank you for your time!…
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…
AWK script: Finding number of matches that each element in Col2 has in Col1
I want to compare two columns in a file as below using AWK, can someone gives a help please? e.g. Now I want to use AWK to implement the following algorithm to find matches between those columns: Expected result: So I want to write the above code in AWK script and I find it too complicated for me as I