Skip to content
Advertisement

Tag: sed

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 – read the book Effective

Match two lines, replace with three lines

I need to use sed to replace every matching two-line pattern with a three line pattern. Here’s my input file (tempfile.txt). Basically, if a client-hostname “HOSTNAME”; is missing, then it should be replaced with a tab and then a newline. My attempt: sed ‘N; /hardware.*}/d; P; D’ tempfile.txt The result is: This is my desired output. So as you can

sed substitute with partial string

Is it possible to replace the last 5 characters of the line with the last 4 characters of the line in sed? My filenames can be any length but the end is always predictable i.e. the part I want to substitute is always 5 characters from the end Answer Just match them separately, and omit the undesired character: Another approach

Grep lines from a file in batches according to a format

I have a file with contents as: Hi welcome ! Chunk Start Line 1Line2! Chunk Start Line 1 Line 2 Line 3 ! Chunk Start Line 1Line 2Line 3Line 1Line 2Line 3Line 4Line 5Line 1Line 2Line 3Line 4 Now, everything beginning with “! Chunk Start” and before the next “! Chunk Start” is a chunk, i.e. the lines between “!

Sed command in linux

How do I extract URL’s from a file? My file name is URL_name.txt This file has a lot of url inside. It looks like this: Here is my idea, I want to remove everything before URLs then I can remove everything after URL. How do I use sed command deal with it? The output should be http://www.google.com/ http://www.stackoverflow.com/ Answer You

Advertisement