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
Tag: grep
How to find all files on a *NIX server containing a certain string
I want to produce a list of every file on my server that contains a certain email address within the file. Starting with htdocs and all of its sub-directories. I am using this command: I seem to be getting the files that contain the string, but I am alos getting a listing of all directories, which I do not want
How to “grep” in array with dot “.” precisely?
I’m trying to check if the user input $1 exist in an array. And here is my code: What I expect is only “aaa.bbb.ccc” or “ccc.ddd.aaa” can be found. However, in this case, like “aaa” or “ccc” can also pass the validation. Seems like the dot is not treated as part of the string. Should I use regex or other
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:28:42 +0000]. I have searched and look at this
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 issues when using two files – I’ve tried everything
I have two files (recode and reads) that were built and saved with nano command and I want to compare what has on recode to reads and extract the lines in reads that overlaps. I have been trying to create a when loop with the previous logic on mind, but without success so far. The output data is not matching
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 manpage of grep: A regular expression
How to grep two IP addresses and increase the value of the last number?
I’m pretty new to Linux and writing scripts etc. I have this task where I need to find an IP-address from a database and then grep a bunch of files with this IP and the next one to see, if they have any presence there. Currently I have to first write: and then And I have to manually change 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 that separately for all headers?):