![]() There are times when we want to get the line numbers against the matching string. How to Find the Line Numbers Against Matching Input using -n The output returned all the lines that do not contain "berries". Let's say, if we want to get all the lines that do not contain the word "berries", the command would look like this: grep -v "berries" fruits.txt We can reverse the results of the grep command to include non-matching results. Output: How to Select the Non-Matching Lines using -v It should match all occurrences of "berries" regardless of their case. Let's find the word "berries" from our sample file. We can command grep to return results while ignoring the case of the matching string. Here's the output: How to Ignore Case Distinctions using -i If we want to find the string "fruit" in the file fruits.txt, we can do so like this: grep "fruit" fruits.txt Contents of fruits.txt How to Find a Matching String with grep Melons – watermelons, rockmelons and honeydew melons Tropical and exotic – bananas and mangoesīerries – strawBERRIES, raspberries, blueberries, kiwifruit and passionfruit Stone fruit – nectarines, apricots, peaches and plums In the coming examples, we will use the file fruits.txt with the following content: apples and pearsĬitrus – oranges, grapefruits, mandarins and limes ![]() -c: Count the number of occurrences of the provided pattern.-w: Find the exact matching word from the input file or string. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |