grep

Read lines from a file, grep in a second file, and output a file for each $line

只愿长相守 提交于 2021-01-27 13:21:26
问题 I have the following two files: sequences.txt 158333741 Acaryochloris_marina_MBIC11017_uid58167 158333741 432 1 432 COG0001 0 158339504 Acaryochloris_marina_MBIC11017_uid58167 158339504 491 1 491 COG0002 0 379012832 Acetobacterium_woodii_DSM_1030_uid88073 379012832 430 1 430 COG0001 0 302391336 Acetohalobium_arabaticum_DSM_5501_uid51423 302391336 441 1 441 COG0003 0 311103820 Achromobacter_xylosoxidans_A8_uid59899 311103820 425 1 425 COG0004 0 332795879 Acidianus_hospitalis_W1_uid66875

Using grep to find string with brackets

旧巷老猫 提交于 2021-01-27 02:37:09
问题 I have some problems with the grep command. I have the following two files in my folder: test.dat: fdf bla(fd_bla_bla) =& bdf bla test2.dat fd fd fij d bla(fdf) fdjk bla Now I search for the bla having brackets after it with grep 'bla(*)' * but it just gives me the entry of the first file...Do you have an idea why? 回答1: You need regular expressions to do that match. egrep "bla\(.*\)" *.dat will give the correct result. 回答2: your grep 'bla(*)' * won't work, because it looks for bla) or bla((((

Using grep to find string with brackets

谁说我不能喝 提交于 2021-01-27 02:36:59
问题 I have some problems with the grep command. I have the following two files in my folder: test.dat: fdf bla(fd_bla_bla) =& bdf bla test2.dat fd fd fij d bla(fdf) fdjk bla Now I search for the bla having brackets after it with grep 'bla(*)' * but it just gives me the entry of the first file...Do you have an idea why? 回答1: You need regular expressions to do that match. egrep "bla\(.*\)" *.dat will give the correct result. 回答2: your grep 'bla(*)' * won't work, because it looks for bla) or bla((((

Using grep to find string with brackets

北战南征 提交于 2021-01-27 02:36:19
问题 I have some problems with the grep command. I have the following two files in my folder: test.dat: fdf bla(fd_bla_bla) =& bdf bla test2.dat fd fd fij d bla(fdf) fdjk bla Now I search for the bla having brackets after it with grep 'bla(*)' * but it just gives me the entry of the first file...Do you have an idea why? 回答1: You need regular expressions to do that match. egrep "bla\(.*\)" *.dat will give the correct result. 回答2: your grep 'bla(*)' * won't work, because it looks for bla) or bla((((

How to recursively grep the pattern inside the directory?

ε祈祈猫儿з 提交于 2021-01-03 08:45:41
问题 I would like to grep all string patterns which are start with the: student_ , then any numbers of symbols(letters and digits) and end with the .tcl 回答1: grep "student_[[:alnum:]]*\.tcl" * 回答2: If you're using vim 7, it comes with a build in grep function that puts the result in a quicklist-window. try :vimgrep /^student_/ **/*.tcl ** makes the search recursivelly To search in current directory only, use: :vimgrep /^student_/ *.tcl read more @ vim.wikia.com 来源: https://stackoverflow.com

How to delete all lines before the first and after the last occurrence of a string?

纵然是瞬间 提交于 2021-01-02 06:00:26
问题 cat grab.txt My Dashboard Fnfjfjf. random test 00:50 1:01:56 My Notes No data found. Change Language + English Submit Estimation of Working Capital Lecture 1 Estimation of Working Capital Lecture 2 Estimation of Working Capital Lecture 3 Money Market Lecture 254 Money Market Lecture 255 Money Market Lecture 256 International Trade Lecture 257 International Trade Lecture 258 International Trade Lecture 259 Terms And Conditions 84749473837373 Random text fifjfofifofjfkfkf I need to filter this

How to add a # before any line containing a matching pattern in BASH?

爱⌒轻易说出口 提交于 2020-12-28 09:56:26
问题 I need to add a # before any line containing the pattern "000", e.g., consider this sample file: This is a 000 line. This is 000 yet ano000ther line. This is still yet another line. If I run the command, it should add # to the front of any files where "000" was found. The result would be this: #This is a 000 line. #This is 000 yet ano000ther line. This is still yet another line. The best I can do is a while loop, like this, which seems too complicated: while read -r line do if [[ $line ==

Extract value from a list of key-value pairs using grep

故事扮演 提交于 2020-12-26 11:00:59
问题 I have a string containing a list of key-value pairs like this: "a:1,b:2,c:3". I would like to extract a value for a specified key so that e.g. I would get "1" for "a". I was planning to do it with a regex like this: '(?<=(^|,)$KEY:)^,*' but it seems grep doesn't support lookarounds. (I'm not even sure this regex works correctly.) Is there another way? 回答1: You may use grep -oP "(?:^|,)$KEY:\K[^,]+" The -o option outputs matches. -P enables PCRE engine. The double quotes are necessary for

Extract value from a list of key-value pairs using grep

不羁岁月 提交于 2020-12-26 10:56:03
问题 I have a string containing a list of key-value pairs like this: "a:1,b:2,c:3". I would like to extract a value for a specified key so that e.g. I would get "1" for "a". I was planning to do it with a regex like this: '(?<=(^|,)$KEY:)^,*' but it seems grep doesn't support lookarounds. (I'm not even sure this regex works correctly.) Is there another way? 回答1: You may use grep -oP "(?:^|,)$KEY:\K[^,]+" The -o option outputs matches. -P enables PCRE engine. The double quotes are necessary for

Do not merge the context of contiguous matches with grep

China☆狼群 提交于 2020-12-08 05:46:09
问题 If I run grep -C 1 match over the following file: a b match1 c d e match2 f match3 g I get the following output: b match1 c -- e match2 f match3 g As you can see, since the context around the contiguous matches "match2" and "match3" overlap, they are merged. However, I would prefer to get one context description for each match, possibly duplicating lines from the input in the context reporting. In this case, what I would like is: b match1 c -- e match2 f -- f match3 g What would be the best