Skip to content
Advertisement

Tag: awk

How do I grep out multiple lines of the same pattern?

I have a log file that is filled with exceptions that is not useful to me. It is being generated every two second and when looking at log file that contains 24 hrs of logging it becomes overwhelming to get to the relevant info I need. My logs look something like this: I want to clean up the copy of

Grouping common elements using awk

The following table illustrates a brief snapshot of the data that I wish to manipulate. I am looking for an awk script that will group similar elements into one group. For eg. if you look at the table below: Numbers (1,2,3,4,6) should all belong to one group. So row1 row2 row4 row8 will be group “1” Number 9 is unique

Pass parameter to an awk script file

If I want to pass a parameter to an awk script file, how can I do that ? Here I want to print the first argument passed to the script from the shell, like: Answer your hash bang defines the script is not shell script, it is an awk script. you cannot do it in bash way within your script.

Substitute a regex pattern using awk

I am trying to write a regex expression to replace one or more ‘+’ symbols present in a file with a space. I tried the following: Expected: Any ideas why this did not work? Answer Use gsub which does global substitution: sub function replaces only 1st match, to replace all matches use gsub.

BASH – weird characters coming out from a pipe

I have this script which simply kills an app If I write the kill command manually as a oneliner than it works. But I have to run it as a script which doesn’t work. So I tried to debug it and here is the result Why do I keep getting those strange characters on the kill line? How can i

Bash: add string to the end of the file without line break

How can I add string to the end of the file without line break? for example if i’m using >> it will add to the end of the file with line break: I would like to add yourText2 right after yourText1 Answer If your sed implementation supports the -i option, you could use: With the second solution you’ll have a

How do I add a line of text to the middle of a file using bash?

I’m trying to add a line of text to the middle of a text file in a bash script. Specifically I’m trying add a nameserver to my /etc/resolv.conf file. As it stands, resolv.conf looks like this: My goal is to add nameserver 127.0.0.1 above all other nameserver lines, but below any text above that. In the end I want to

Advertisement