Skip to main content

All Questions

3 votes
3 answers
730 views

Find files matching one pattern, but not another, using grep, awk or sed [duplicate]

I need to locate .php and .pl files that do not contain one string (e.g. aaa), but do contain another (e.g. bbb). I'm currently using this command: find /path/ \( -iname '*.php*' -or -name '*.pl*' \) -...
Krackout's user avatar
  • 2,742
4 votes
4 answers
691 views

grep multiple patterns with differing number of matching groups?

I'm trying to tally insertions and deletions from git diffs. I have the following, which when piped one or more strings of the form "4 files changed, 629607 insertions(+), 123 deletions(-)" ...
jawns317's user avatar
  • 143
1 vote
6 answers
1k views

print lines between 1st occurence of 1st pattern to last occurence of 2nd pattern with AWK

I have a datafile, with dates in 2nd column # cat datafile -;20210106;-;-;-; -;20210112;-;-;-; -;20210112;-;-;-; -;20210112;-;-;-; ... -;20210217;-;-;-; -;20210217;-;-;-; -;20210217;-;-;-; -;20210217;-...
Sollosa's user avatar
  • 1,951
0 votes
2 answers
396 views

Equivalent of grep string matching to sed & awk [closed]

I am currently processing large files looking for unmatched patterns. I am using grep to achieve this. And for some reason, grep ignores/excludes some of the potential unmatched patterns. Both the ...
user3441801's user avatar
9 votes
12 answers
2k views

How do I print the last sequence of lines between a start and an end pattern?

Answers to this question: How to grep lines between start and end pattern? are not concerned with multiple sequences of lines which fall between the match patterns. Thus, for example, sed -n '/...
einpoklum's user avatar
  • 9,653
0 votes
2 answers
1k views

grep patterns and keep matches on the same line

From the sample input: cat file.txt ID1 sample1 sample2 match1 sample3 ID2 sample4 match2 matchABC I would like to obtain sample output, keeping only the matched words on ...
aechchiki's user avatar
  • 243
0 votes
2 answers
220 views

Matching columns of File1 to columns of file 2 and printing them in a file using awk

I am new to awk and trying to compare ":" separated columns 1(eg., chr10) and 2 (eg 10000003) between file1 and file 2 ; and write the matching lines into a new file using awk. File 1: chr10:...
Gul's user avatar
  • 1
0 votes
1 answer
53 views

Grep different kinds of patterns

I have a file that looks like this: 1>>>PROKKA_00001 Transcriptional regulator PadR-like family protein - 137 aa >>tr|E5G076|E5G076_ARAHY Ara h 1 allergen OS=Arachis hyp (619 aa) 37.3%...
Susheel Busi's user avatar
-4 votes
1 answer
371 views

Extract data between two patterns from a huge (forced) text file

I have filename.json. If I parse it in terminal with file filename.json output is: filename.json: UTF-8 Unicode text, with very long lines wc -l filename.json 1 filename.json If I parse it ...
CCC's user avatar
  • 79
0 votes
2 answers
151 views

Pattern recognition betweel two sentences in a file which has spaces and special characters?

I have a file in which I want to print all the lines between two patterns. Pattern1 = # Begin TRACE A Data and Pattern 2 =# Done Data $capture, I want to print every line between pattern1 and pattern2....
CCC's user avatar
  • 79
1 vote
1 answer
344 views

Match lines between two patters using sed just once [duplicate]

Given: sed -e '/pattern1/,/pattern2/!d' file.org How can I match the first occurrence of the lines between pattern1 and pattern2, but not the rest? For example: pattern1 aaaa pattern2 pattern1 bbb ...
Quora Feans's user avatar
  • 3,865
3 votes
3 answers
780 views

Comparing two files linewise and if pattern of file 1 is not found (fully or partially) in file 2 then print line of file 1

I have two files: file1 (search): 1 GACGGAGGATGCAAGTGTTATCCGGAATCACTGGGCGTAAAGTTTTTTTTT 2 GACGGAGGATGCAAGTGTTATCCGGAAT 3 GACGGAGGATGCAAGTGTTATCCGGAATCACTGGGCGTAAAGCGTCC 4 ...
MSt's user avatar
  • 31