grep

Find all lines between two patterns, EXCLUSIVE of the second pattern?

Find all lines between two patterns, EXCLUSIVE of the second pattern? Consider that I have the file listed below. I need to select all lines from every instance of the regex pattern Word A to before the regex pattern Word D. Word A Word B Word C Word D Word E Word F Word G …

Total answers: 6

Isolate one specific instance of a word in a string

Isolate one specific instance of a word in a string I have a grep command to process the string test-test test I want the command to only show me the "free-standing" word test highlighted, but not test-test. However, when I run echo "test-test test" | grep -w "test" I get all test occurences highlighted. Is …

Total answers: 4

Grep a log file for SQL queries and their execution time

Grep a log file for SQL queries and their execution time I have an application log file that also captures the execution time for each executed SQL statement, like below:- Sample logs: I 2023-11-15 07:18:00.743Z 1760463 37 ZVRwqItu6aw-b8eejMLI_gAAAAU 1@45077318@A PHP Request Summary: 7 warnings/errors on 6 lines I 2023-11-15 07:17:15.927Z 1773299 99 ZVRwenUWDwrXl_9NnC-2vwAAAAM 1@45077318@A There …

Total answers: 2

Unable to grep foreign language in shell script

Unable to grep foreign language in shell script I am a newbie in shell scripting, I have a text which contain text in following format:- "some foreign language",’corresponding ID to text’ for example:- "Назад",IDC_SSB_DLG_BACK_BTN I need to find the text related to ID and save in in text file. Here my sample script:- #!/bin/sh target_file=$1 …

Total answers: 2

How to use variable in Find and grep command?

How to use variable in Find and grep command? find command to get files have part of their names as date ($Y variable that has date in the script) Y=(date -d "1 day ago" "+%Y-%m-%d") find /log/bssuser/CDR/Postpaid_CDR_Log/ -type f -name ‘*log_LOG_POSTPAID_CDR’*$Y*.log | grep -H ‘^ORA’ ‘log_LOG_POSTPAID_CDR’*$Y*.log when run this command I got the below error: …

Total answers: 1

find and replace 1 word in all files inside multiple directories?

find and replace 1 word in all files inside multiple directories? i have a problem with a wordpress website which are using external theme made by themefie.com , this website is restricted by google and some how google restricted my website too because i am using there theme . I’ve searched for themefie.com inside my …

Total answers: 1

Remove a fixed sequence of lines and everything that comes after that

Remove a fixed sequence of lines and everything that comes after that The input is the file input.txt, that contains these rows 5 ccc 36 52 1 2 3 78 69 aaa bb The fixed sequenze of lines is this 1 2 3 I want to remove this sequence and everything that comes after that, …

Total answers: 2

Counting matches with grep, when multiple matches per line are possible

Counting matches with grep, when multiple matches per line are possible The standard usage of grep is to return lines that match a pattern. If a line can contain several matches of the pattern, how can I count each match individually, not the total number of matches? Asked By: Arunabh Bhattacharya || Source The grep …

Total answers: 3

How I can aggregate my matches from find command by grepped values?

How I can aggregate my matches from find command by grepped values? I am looking for all occurences of <source_model>.*</source_model> at any files located at ./vendor/magento/*/etc/adminhtml/system.xml: find ./vendor/magento/ -type f -path */etc/adminhtml/system.xml -exec grep -P "<source_model>.*</source_model>" {} + But the output is in a form of: ./vendor/magento/module-authorizenet-cardinal/etc/adminhtml/system.xml: <source_model>MagentoConfigModelConfigSourceYesno</source_model> And I want to extract the value: …

Total answers: 1

grep -rlw but only on files that are as newer than 7 days?

grep -rlw but only on files that are as newer than 7 days? Currently, I use this version of grep -rlw grep -rlw . -e "string_to_search" To search for overall files containing "string_to_search". I want to modify it to find files that are not older than 7 days. How do I do it? grep -rlw …

Total answers: 1

How to find a string in files, said string including line breaks, ", @

How to find a string in files, said string including line breaks, ", @ I know grep allows me to search for a string in files, however I did not manage to find the right method to search for the following string: "snapshot3" : { "@custom_name" : true So the string I am looking for …

Total answers: 1

Can I extract complete dates from file with grep command?

Can I extract complete dates from file with grep command? I need help using grep to extract a zoned date time from a file on a Linux system. Source file is a XML with the data below: <item start="20231010073000 +0100" stop="20231010100000 +0100">…</item> And I need to extract the complete start date, but with grep I …

Total answers: 4

Using find in order to detect a magento module

Using find in order to detect a magento module At magento routes are located in adminhtml/routes.xml each module has a folder named adminhtml with a file routes.xml each module has its own folder. In other words I have the following file structure: vendor + MyModule ++ etc +++ adminhtml ++++ routes.xml + AnotherModule ++ etc …

Total answers: 2

How to remove empty lines containing only ends of lines $?

How to remove empty lines containing only ends of lines $? I have a file: cat -E extracted_numbers.txt 11.47$ 0.32$ $ 1.37192$ -4.$ 7.$ 20.$ 13.$ $0. 15000$ 15000.$ $ 2.87$ $.6 47.$ $00. 0.0000000000000000$ 0.0000000000000000$ $ 0.0000000000000000$ 0.0000000000000000$ $ 0.0000000000000000$ 0.0000000000000000$ $ 0.0000000000000000$ 0.0000000000000000$ $ 0.0000000000000000$ 0.0000000000000000$ $ 0.0000000000000000$ 0.0000000000000000$ $ 0.0000000000000000$ 0.0000000000000000$ $ …

Total answers: 1

Getting a short string from a long one without spaces

Getting a short string from a long one without spaces I have a file with a huge string without spaces in it (something like: "A":123,"B":456,"C":789…) I want to get X amount of chars before and after a specific value (like what is around "B"). But, if I use cat, because the string doesn’t have spaces, …

Total answers: 1

Deleting files whose filenames match strings contained in a file

Deleting files whose filenames match strings contained in a file There is a text file, del.txt, containing a list of randomly-generated identifying strings, for example: 07ckv978yk0 HuinLBoZHcY _oR7ccXiunY I would like to delete any files whose filenames contain any of the identifying strings. The filenames would be in the format of 20191223_abcdef_07ckv978yk0.json, where the matching …

Total answers: 3

Grep Multiple Pattern located in different lines and print in the same line

Grep Multiple Pattern located in different lines and print in the same line I’m trying to find a way to grep information in the file that located in the different lines and one of the pattern is contain pattern of date and time. below is the input unwantedtext unwantedtext unwantedtext unwantedtext 8/1/2022 6:15 (1st required …

Total answers: 5

How to check logs greater than certain duration using grep?

How to check logs greater than certain duration using grep? grep -lw -e ‘0123456789’ application.log_2023-07-* I want logs greater than 2023-07-*, how do I achieve it? Similar Question: grep particular log entry greater than specific time Asked By: achhainsan || Source You’ll need to use at least two patterns (in the same line), one for …

Total answers: 1