Skip to content

Tag: grep

How can I show only some words in a line using sed?

I’m trying to use sed to show only the 1st, 2nd, and 8th word in a line. The problem I have is that the words are random, and the amount of spaces between the words are also random… For example: Is there a way to get this to output as just the 1st, 2nd, and 8th words: Thanks for any

Search and Replace under linux?

I tried the following but not adding ” this example I want to replace FILENAME_LOGIN to ‘login.php’ Tried this: However, it gives me login.php not ‘login.php’ Thanks Answer You only need sed for this:

Read the log files and get the entries between two dates

I want to extract some information from the access log file that matches a keyword and between two dates. For ex. I want to find log entries between two dates that contains text “passwd”. For now, I am using the following command but not getting the correct results: Date format is [22/Feb/2017:17:…

Why doesn’t grep -lv work?

I want to print out the name of a file if and only if it does not contain the string foo. However, if file contains foo and I run this file is outputted. Why does this happen and what can I do to work around it? Answer -v means to match any line that doesn’t match the pattern. So -lv

Grep Pattern matching- underline

I’ve not been able to find anything online to help so hoping someone may have an idea. What does an underline in an expression mean when using grep? For example: [_a-zA-Z0-9] Could someone help to explain the purpose here? Answer The grep command uses a regular expression as it is also described in the …

Running statistics on multiple lines in bash

I have multiple HTTP headers in one giant file, separated with one empty line. I have approximately 10,000,000 of headers separated with an empty line. If I want to discover trends, like header order, I want to do aggregate headers to a one-liner (how I can aggregate lines ending with an empty line and do tha…