Skip to main content

Questions tagged [pattern-matching]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3 votes
1 answer
138 views

To understand zmv ## patterns

This is zmv command to non-recursively replace any number of spaces with a single underscore (thanks to Stéphane Chazelas, who helped me with it): zmv -- '* *' '${f// ##/_}' And here is a command ...
jsx97's user avatar
  • 71
2 votes
1 answer
268 views

How is the correct syntax for a more complex case statement?

case "$1","$name" in -py | --python | --python3,*) if [[ "$name" =~ \..+$ ]]; then That doesn't catch stuff, which actually it should, like… USERNAME@HOSTNAME:~$ ...
futurewave's user avatar
-1 votes
5 answers
71 views

multiline grep search into separate files per occurence

I have a file as following: example.txt -1 15 1 0 0 11 -1.0000E+001 1.0000E+001 -1.0000E+001 2 0 0 11 1.0000E+001 1.0000E+001 ...
Honza S.'s user avatar
  • 101
0 votes
1 answer
51 views

Retrieve the Following Occurrence of the String 'PWD' Once the Given String is Located

Below is my sample test.log file export SQRDIR=/v/orahome/Middleware/Oracle/bin64 export OID=ap0092 export PWD=pass1 export FDPWD=pass1 export AP0085_PWD=pass1 export SVR=AFFPROD export ...
Ashar's user avatar
  • 511
1 vote
3 answers
346 views

awk print between lines when "/" is part of the name

I need to print lines between those that contain a "/" in the name. I tried with: awk '/+SOLUTION/ESTIMATES/,/-SOLUTION/ESTIMATES/' $F > fil$F and awk '/+SOLUTION"/"ESTIMATES/,/...
euge1780's user avatar
0 votes
0 answers
30 views

match files with regexp and move them

My problem is like this: The original folder "datasets to optimize" contains 1000s files whose names contain the following pattern: variable 2-3 dots or 1 dot with numbers, as in 1.87.184 ...
user1420275's user avatar
0 votes
4 answers
74 views

Wrap specific string with characters

For example, in a large file I might have: This is a /16 text file I'd like to change it to the following: This is a [[[/16]]]] text file Would like to match the exact string /16 Is there a way to ...
Proletariat's user avatar
2 votes
0 answers
57 views

Pattern list in bash extglob containing a / and a |

Here is a transcript of commands (and their output) that explains my problem: /tmp/example $ shopt -s cdspell on checkwinsize on cmdhist on complete_fullquote on direxpand ...
Happy Green Kid Naps's user avatar
1 vote
2 answers
48 views

replace both filename and filename's content relying solely on pattern found on the name-of-the-file

I'd like to know if it's possible to replace both filename.ext and a matched pattern inside its content regarding a pattern founded on the filename itself using sed (and grep also, maybe?). Let me ...
dAllARA's user avatar
  • 33
1 vote
1 answer
2k views

Searching for a pattern in a binary file using python script

I want to find repeated copies of the config section within the partition dump (binary file), using pattern and 'magic' header. The config section always starts with 202 '0xff' bytes followed by 4 ...
minto's user avatar
  • 535
0 votes
1 answer
82 views

Bash: Difference between "Pattern Matching" and "Filename Expansion" in the context of parameter expansions that do matching

Edit: Question ansewered by Gordon Davisson's comment I was reading the GNU Bash manual, and I noticed that there are basically three types of "Parameter expansion" that do pattern matching: ...
Sebastian Carlos's user avatar
3 votes
3 answers
728 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
690 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
0 answers
68 views

does "find -name " matches the whole path or just the basename?

I was getting inconsistent results with pattern matching using -name, -iname, especially when looking for files -type f or directories type -d. Can someone explain under which circumstances -name ...
ricardo3889's user avatar
0 votes
3 answers
719 views

Glob pattern matching comma separated numbers

I want to write a glob pattern to match numbers separated by commas. What would the pattern be like? Here are some examples 5 5,8,13 Have started with the following, but there some problem with it, ...
Vera's user avatar
  • 1
0 votes
2 answers
57 views

How to combine files from incrementing directories into one directory

I have a directory structure that follows this kind of pattern: - Dir 01 (Disc 1) \ - Dir 01 (Disc 1).iso - Dir 01 (Disc 2) \ - Dir 01 (Disc 2).iso - Dir 01 (Disc 3) \ - Dir 01 (Disc 3).iso - ...
bashing_pumpkins's user avatar
-2 votes
1 answer
52 views

Determining repetitions of 8-tuples [closed]

I have 16 collections of 8 numbers (11 12 11 44 11 12 11 23) (12 21 11 44 11 12 11 23) (11 42 21 13 12 21 31 14) (11 42 21 13 12 21 11 34) and so on I want to find whether there are repetitions of ...
Vera's user avatar
  • 1
2 votes
2 answers
2k views

Sed based on 2 words, then replace whole line with variable

I have a txt file looking like this, 1:Ana:apple:08:00:wait 1:Joe:banana:08:30:wait 1:Oscar:orange:08:45:ready 1:Monica:apple:08:50:ready 1:Mark::orange:ready I have to find only the first line that ...
Claudio Del Prete's user avatar
0 votes
3 answers
585 views

Need to grep the word right next to or below a pattern

I have a file with the following lines in i: .......... FROM ABCD_EXT .......... FROM HEG_EXT1 .......... from xyz_EXT .......... FROM abd_EXT2 ..........where QWT_EXT.SID=POI_EXT....
TexGC's user avatar
  • 31
0 votes
1 answer
148 views

how to detect unbalanced special characters in string

I'm wondering what would be the best way (likely using grep or ack) to return lines containing unbalanced special character sets in a string? For example, if the string were: bqM#+t1U"OyBGhk]ozVG[...
irishwristwatch's user avatar
2 votes
2 answers
203 views

How does this glob expression remove colons?

Say we have a file called "Hello World: The easiest program" and its name is saved in a variable called "title". I want to match this with glob pattern matching, but remove the ...
Rudi Österreicher's user avatar
1 vote
2 answers
31 views

How to match the starting of string & then replace some value using the pattern in bash

vm0 host=10.182.35.1 controller=True vm1 host=10.182.35.2 controller=False solution=abc vm2 host=10.182.35.3 controller=True solution=abc vm3 host=10.182.37.4 controller=False solution=xyz vm4 host=10....
Madhavi Deshpande's user avatar
1 vote
2 answers
42 views

How can I delete everything before and afrer match pattern from pdb file?

I'm beginner in bash scripts, but I try to delete everything in my pdb file (test.pdb) before REMARK time 20.00 and from REMARK time 30.00 to the end of this file. I'm using to this sed command, which ...
skywalker's user avatar
0 votes
1 answer
63 views

Remove/move files in a directory with filename timestamp pattern

So I have files that need to remove/move/filter. All files have this pattern like this in a directory, let's say directory frames contain this pattern filename timestamp_in_nanosecond.jpg. And this is ...
Muhammad Ikhwan Perwira's user avatar
0 votes
2 answers
441 views

Extract all links (including multiple links per line) in markdown file

Sample markdown file: cat index.md # Abstract - To achieve [Work Life Balance](./WorkLifeBalance/WorkLifeBalance.md), first understand what it means and what are the requirements. - Develop right **[...
Porcupine's user avatar
  • 2,056
0 votes
1 answer
200 views

Remove certain words and set word at end of string in files

I have a bunch of files that contain strings similar to: Get<1>(abc) Get<2>(xyz) How can I recursively search for all files with the above pattern and remove everything before the first '(...
aWLW's user avatar
  • 101
7 votes
2 answers
2k views

Exclude patterns from glob match

My directory looks like this: $ ls total 0 -rw-r--r-- 1 user user 0 Jun 18 22:44 file0 -rw-r--r-- 1 user user 0 Jun 18 22:44 file1 -rw-r--r-- 1 user user 0 Jun 18 22:44 file2 -rw-r--r-- 1 user user 0 ...
rewire's user avatar
  • 111
0 votes
1 answer
119 views

Sum sizes of certain folders/files with inclusion and exclusion patterns

I'm looking for a tool that gives me the total size on disk of certain folders and files. It should be able to unambiguously include or exclude items and all of their children (folders and files in it)...
ostrich's user avatar
  • 11
1 vote
2 answers
297 views

how to check for existence of multiple patterns in bash

i have several patterns that include ** wildcard, let them be: foo/**/bar.xml foo/**/baz.xml and i have an example dirtree: $ tree foo/ foo/ └── deep ├── baz.xml └── even └── deeper ...
murison's user avatar
  • 163
-1 votes
2 answers
1k views

awk no print if value from file1 not match value in file2

file1: G A 4 H B 3 I C 2 J D 1 file2: M H 6 N H 5 O K 4 P J 3 Q I 2 R I 1 S G 0 T L 1 Desired: M H 6 N H 5 P J 3 Q I 2 R I 1 S G 0 print only rows where $2 from file2 matches $1 from file1 I'm ...
Sollosa's user avatar
  • 1,951
0 votes
2 answers
320 views

match number range with non significative zeros in zsh

I have in a directory files like this : booklet-001.pdf booklet-002.pdf booklet-003.pdf … booklet-997.pdf booklet-998.pdf booklet-999.pdf Then, I whant to match the files numbered from 079 to 256. ...
fauve's user avatar
  • 1,278
1 vote
0 answers
68 views

How to find the PHP file which prints an HTML element with a certain selector?

I store my MediaWiki 1.36.1 website with Skin:Timeless on NameCheap with a shared hosting environment with Cpanel file manager and SSH shell access. In my website, there is a certain footer element ...
searcher's user avatar
2 votes
1 answer
144 views

ZSH expanded variables in [[ ... ]] do not perform globbing

I have extended_glob set in .zshrc. this works as expected: [[ "value" = [a-z]* ]] && echo "globbed" Prints "globbed". But this does not: foo=[a-z]* [[ "...
toni rmc's user avatar
  • 123
5 votes
9 answers
1k views

How to put text inside text automatically?

I need to put one text inside another text. 1) I have a file with list of input values: A1 B2 C3 D4 E5 I have a wrapper pattern which should contain the text: $wgSpecialPageLockdown['...
Lahor's user avatar
  • 123
8 votes
2 answers
2k views

Avoiding non-zero exit code when running `ls` using multiple patterns

Say I have two possible paths I want to list directories and files under on a Linux machine: /some/path1/ /some/path2/ If I do the following in tcsh, I get 0 exit code, if at least one of path1 or ...
shikhanshu's user avatar
0 votes
2 answers
65 views

How to extend a wild card option to include js and ts

I have an alias set as follows: alias ppp='prettier --write "**/*.js"' I want it also to do all my .ts files. I'm quite inept at wild card expressions sadly.
Peter Kellner's user avatar
7 votes
1 answer
316 views

Is "warning: range of the form `[o-b]' is locale dependent" a bug in gawk 4.1.0?

While writing some awk code I was using the --lint option for gawk 4.1.0. To my surprise I get a warning warning: range of the form `[o-b]' is locale dependent but my code has only a foo-bar outside ...
U. Windl's user avatar
  • 1,493
4 votes
3 answers
2k views

Is there a way to make find use shell's extglob shell option?

In short, I instinctively wrote a command like this to find the two files prefix.ext and prefix_suffix.ext down a hierarchy find /some/path -type f -name 'prefix?(_suffix).zip' but it doesn't work. ...
Enlico's user avatar
  • 1,677
5 votes
1 answer
844 views

Using anchor ^ pattern when using less / search command

When navigating through Linux man pages, sometimes you need to query the meaning of flags like -p or -al in the man pages. The default text reader for man pages is less and I'm trying to use the / ...
Silver137's user avatar
  • 329
0 votes
1 answer
572 views

select lines in file with same string pattern

Let´s suppose I have the following file.txt: asiub sj abq b aia ainp oo test = 123d sub ,. aiba 87ab test = 129szs bq test = aqua ayqvq 133s I want to print only the lines of file.txt that contain ...
aaaaa's user avatar
  • 141
0 votes
1 answer
159 views

Rsync: Clone structure for specific pattern [duplicate]

How can one recursively copy all files of a specific pattern (*.tpl) using rsync? Example: /etc/test.tpl /etc/dir/test.tpl /etc/dir/**/test.tpl
Spyros's user avatar
  • 145
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
0 answers
50 views

Capturing comment character from matching pattern

I would like to pick out lines from a file matching # Mode: org # can be any comment character for the programming language of the file. Rather than #, in could also be any of ; or !, with any ...
Vera's user avatar
  • 1
0 votes
2 answers
105 views

how to perform multi substitution with sed on a block of text?

I have text file, and in it has a block that has pattern like below: # cat file Jit .... enabled=false Jit ..shoes.. From=2021-01-01 Jit ..gloves.. From=2021-01-01 so I want to change all of these ...
Sollosa's user avatar
  • 1,951
-1 votes
4 answers
2k views

Linux - Find all occurrences of a certain pattern in a line of a file

I have a file in Linux which contains a line like : (memberOf=CN=Group1)(memberOf=CN=Group2)(memberOf=CN=Group3)(memberOf=CN=Group4) My goal is to populate the list of groups that is present in the ...
Deep's user avatar
  • 1
0 votes
1 answer
405 views

How to not print the output if the second pattern does not match

file1: pattern1 a b c end cmd=> cat file1 | sed -n '/pattern1/,/pattern2/p' output=> pattern1 a b c end How to not print the output if the second pattern does not match? Desired output: ...
Priyatharshini Ganesan's user avatar
1 vote
6 answers
3k views

match some or all patterns with awk

I have a small problem with awk multiple pattern matching which I cannot figure out. I have the following awk line: awk '/pat1/{v1=$4; next} /pat2/{v2=$5; next} /pat3/{v3=$6;next} /pat4/{v4=$5; print ...
lucian's user avatar
  • 299
2 votes
1 answer
44 views

Loop through file with unique identifer and compute cumulative sum

I have a large text file, as shown below, where column1-colum3 define a region and fourth column is unique identifier. The column 6 is assigned value of the region. chr6 26204834 26204839 ...
CN_229133's user avatar
  • 115
1 vote
2 answers
980 views

Why does "grep -w" match words followed by hyphen/minus ("-")?

I need to ask you about using grep command in a Bash script in Debian. I have got for example file with these lines: /fruit-/apple.txt /fruit-/banana.txt /fruit-/samples /vegetables-/carrot.txt /...
SED85's user avatar
  • 45
2 votes
1 answer
1k views

How can grep return a different number of matches?

I need to grep a file (24 lines) into two files (which are kind of big). The original files contains 24 lines that resemble this string: AATGGACGCTTAAC[A|C|T][A|C|G]CGGC[A|T]TCGGAT I do the following:...
gabt's user avatar
  • 381