Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [pattern-matching]

The tag has no usage guidance.

0
votes
4answers
42 views

How to extract word which has only numbers separated by 'dot'

From below lines abcd efgh ijhk lmn opqrs 9.0.8.2c tuv wxyz abcd efgh ijhk lmn opqrs 8.1.3.9b How to extract only 9.0.8.2c 8.1.3.9b
0
votes
1answer
31 views

Sed search and delete matching two patterns one of which is a variable

I have a file that contains multiple instances of code that I need to delete. Here is an example: !/bin/bash mkdir /rootdir/pipeline_runs/oncology/analysis/sample_1_NA172_1 cd /rootdir/pipeline_runs/...
-3
votes
1answer
62 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 ...
1
vote
2answers
41 views

grep contents of one list with another

I have 2 files and I want to grep on them List1 ACY1 RPL3 RPL4 List2 1 ABHD14A-ACY1 2 ACY1 3 RPL34 4 RPL21 5 RPL3 6 RPL41 I tried something like this grep -Fwf list1.txt list2.txt ...
0
votes
1answer
35 views

How to negate Bash's Regular Expression Matching Operator

Bash has the =~ regular expression matching operator. Here is an example of using it: #!/bin/bash input=$1 if [[ "$input" =~ "[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]" ]] # ^ ...
-2
votes
2answers
50 views

Find longest stretch of pattern from centre of sequence

How to calculate the longest consecutive pattern of C/T anywhere in sequence and longest consecutive pattern of C/T from centre CCCCTGTTGCCAAACAATGC TTTTCCCGCCTTTGGCCTAC ...
0
votes
1answer
12 views

how to match a column of a file 1 to text of another file 2 then if it matches print file 2

File 1 Name,TaxID,Lineage,Count,Proportion_All(%),Proportion_Classified(%) Acaryochloris marina,155978,Bacteria;Cyanobacteria;;Synechococcales;Acaryochloridaceae;Acaryochloris,4,0.000218669,0....
1
vote
2answers
161 views

Use sed to print selected lines within a range

Consider the simplified file AAA BBB CCC1 DDD EEE CCC2 DDD FFF GGG CCC3 HHH I can pick out the range EEE to FFF with sed -n '/EEE/,/FFF/p' Suppose though that I want to print any line containing C ...
4
votes
5answers
252 views

Count the longest stretch of consecutive patterns

I have a sequence file: $ cat file CACCGTTGCCAAACAATG TTAGAAGCCTGTCAGCCT CATTGCTCTCAGACCCAC GATGTACGTCACATTAGA ACACGGAATCTGCTTTTT CAGAATTCCCAAAGATGG I want to calculate the longest stretch of C+T. I ...
0
votes
2answers
181 views

grep multiple patterns with different context

I have a file roughly like header_one param1 param2 ... data_one data1 data2 data3 data4 ... header_two param1 param2 ... data_two data1 data2 data3 data4 I'd like to extract all header blocks ...
0
votes
2answers
56 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....
0
votes
1answer
38 views

For a given string(2 or 3 word) in a .txt file and print the whole line. [duplicate]

My .txt file contains these kind of content : The Law and Lawyers of Pickwick, by Frank Lockwood 21214 Frankenstein, by Mary Wollstonecraft 20 The first ...
0
votes
1answer
127 views

print out lines if first three columns match the first three columns in another file

I have file1 which has 3 columns and file2 which has 8 columns. What I wanted to do was if the first 3 columns in file 2 were found in file 1, then print out the entire 8 columns in file 2. I have ...
0
votes
1answer
55 views

Pattern recognition and summing columns between two csv/excel files

I have two files, in which one has data on each person's start date, increment, promotion and other details, and the other file has their research output over the years. Can a script be written in ...
1
vote
1answer
59 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 ...
3
votes
3answers
100 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 ...
3
votes
2answers
400 views

How to grep MATCH colored input?

Say I have output from a command that is colorized for the terminal. I want to match any line that contains the color yellow. How can I do this in grep, eg: mycommand -...
0
votes
3answers
795 views

Grep for word stem and print only word (and not line)

I'm trying to print only a matching word that are found through a regular expression. Below, I want all the OPENSSL_NO_* options that are present in the source code: $ grep -IR OPENSSL_NO fuzz/asn1.c:...
0
votes
0answers
55 views

grep a sequnce of 'AB<anything>CDE' [duplicate]

I want to grep for 'AB...CDE', where ... stands for anythings until CDE first occurs. I have tried grep 'AB*CDE' filename but this matches til the last occurrence of CDE. How can fix this? ...