Skip to content
Advertisement

Tag: awk

Using awk to trim away parts of a text file outside 2 patterns

I’d like an elegant awk solution to edit the lines in a file. So far I’ve only managed to complete the task using 2 sed commands and 1 awk command. Each file is composed of a header of indeterminate length, followed by the data I want to capture, then a footer which always starts with the same string (WATER). The

Using bc as daemon in BASH shell from awk

In BASH environment I can communicate with bc program using fifo. But in awk I can write but no read with getline function. How can I read from “/dev/fd/4” in awk. My awk version is: mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan Thanks Laci Continued: I did some further experiment and I summarize my result. Awk script language

Print previous line if condition is met

I would like to grep a word and then find the second column in the line and check if it is bigger than a value. Is yes, I want to print the previous line. Ex: Input file Output Now, I want to search for BB and if the second column (2 or 0.1) in that line is bigger than 1,

awk sum every 4th number – field

So my input file is: I want to sum the numbers then write it to a file (so i need every 4th field). I tried many sum examples on the net but i didnt found answer for my problem. My ouput file should looks: Thanks! Update: The problem is the same. I want to sum the 3th numbers (But in

Use Bash variable within SLURM sbatch script

I’m trying to obtain a value from another file and use this within a SLURM submission script. However, I get an error that the value is non-numerical, in other words, it is not being dereferenced. Here is the script: When I run this as a normal Bash shell script, it prints out the number of procs correctly and makes the

How to clean up masscan output (-oG)

I have a problem with the output produced by the masscan utility with the -oG options (“grep-able” output); for instance, it outputs this: The above is neither very readable nor easy to understand. How can I use Linux command-line utilities, e.g. sed, awk, or grep, to output something as follows, using the file above? As you can see, the output

How to delete duplicated rows based in a column value?

Given the following table Using a bash shell script based in Linux, I’d like to delete all the rows based on the value of column 1 (The one with the long number). Having into consideration that this number is a variable number I’ve tried with awk ‘{a[$3]++}!(a[$3]-1)’ file But I am not getting the result which would be something like

cut or awk command to print first field of first row

I am trying print the first field of the first row of an output. Here is the case. I just need to print only SUSE from this output. Tried with cat /etc/*release | awk {‘print $1}’ but that print the first string of every row Answer Specify NR if you want to capture output from selected rows: An alternative (ugly)

Advertisement