Questions tagged [pattern-matching]
The pattern-matching tag has no usage guidance.
0
votes
1answer
36 views
Log the files found with the linux find and sed command
I have a folder with txt, html, jpg and png files.
Now I want to go over all textbased files (txt and html) and start a search and replace.
I did the following and it is working fine:
find ./ -...
1
vote
1answer
25 views
Compare two text files, extract matching rows of file2 plus additional rows
have been mocking around with this too long and tried grep, join, awk but I cant get the parameters right. I need to get the command right.
I have got two text files.
cat file1
@ABC:11:ABC:1:...
2
votes
1answer
25 views
WildCard Find Replace CP
I'm trying to replace files that match a particular pattern* on CentOS, but it is not working.
I initially wrote:
cp example.com/(*)/orm-mysql/build/conf/(*)-conf.live.php example_dev.com/$1/orm-...
2
votes
4answers
367 views
Parse all strings of specific length?
I've exported my email archive of 10 years which is very large.
I want to parse all the text for any string that is 64 characters long in search of a bitcoin private key.
How can I parse strings of ...
0
votes
4answers
50 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
44 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
73 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
81 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
113 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
51 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
330 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
253 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
223 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
69 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
39 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
143 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
60 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
61 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
107 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
516 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
1k 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
56 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?
...
7
votes
1answer
660 views
Is there a Unix command that searches for similar strings, based mostly on how they sound when spoken?
I have a file of names, and I want to search within it, not caring too much about whether I have spelled the name ( that I am searching for ) correctly. I know that grep has quite a bit of ...