Questions tagged [regular-expression]

Regular expressions are a means of matching a pattern of characters within a string.

Filter by
Sorted by
Tagged with
5 votes
4 answers
360 views

How to make grep for a regex that appear multiple times in a line

I want to grep a regex. The pattern I am searching for may appear multiple times in a line. If the pattern appeared many times, I want to separate each occurrence by a comma and print the match only ...
user avatar
0 votes
1 answer
38 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 '(...
user avatar
  • 101
0 votes
2 answers
65 views

Convert a text file with tabs and whitespaces to csv (semicolon separated in this case) [closed]

I have a file with a "table" made in a text file. To have the text aligned in columns a mixture of whitespaces and tabulator have been used. Now I need to convert this file into a file with ...
user avatar
  • 1
0 votes
1 answer
30 views

(sed or an alternative in sh) if a line does not contain a dot (.). Then add XX at the end

Background information: Data exchange via csv between 2 programs. I have the following csv from program 1: > timestamp; name ; value > 1655709562;Var 1 Float;65.0 > 1655709562;Var 2 Float;...
user avatar
  • 3
0 votes
0 answers
17 views

How to open a bunch of links in new tabs?

I'm working with html with 50-100 hrefs per page, so its too much time wasted in manually opening the links. I Was trying with javascript inside the firefox web console var links = document.links; for ...
user avatar
  • 119
-1 votes
3 answers
51 views

Compare data from two files and update the 2nd file in Shell

I need to compare data from two files and based on the condition I need to update the 2nd file in Shell. I have two set of files. The first file contains data as NUMBER,ID 748378,9508 473738,7892 ...
user avatar
3 votes
2 answers
196 views

Regular expressions using sed: what does `'1{/^$/d}'` do?

While going through a shell script I came across the line sed '1{/^$/d}' $file1 >> $file2 What is the significance of sed '1{/^$/d}' here?
user avatar
0 votes
2 answers
35 views

sed: Remove value and insert at the end

I have following Strings "1 Michael" "2 John" ... and I´d like to transform them into "Michael 1" "John 2" .... How can I do this? The Strings are stored in ...
user avatar
  • 3
0 votes
4 answers
38 views

Changing the name of a file based on a part of its original name that are between the first two instances of a character

I am trying to change the names of my files based on the string between the first two instances of "|". This is what my problem looks like: >1234|interest1|randomstuff1.txt >5678|...
user avatar
0 votes
1 answer
40 views

Using grep to extract IP through adb shell

I'm trying to create a one-line, platform-independent solution for finding the local IP address of a Android device with adb shell and grep (the internal grep on my android device). I have a solution ...
user avatar
  • 101
1 vote
1 answer
47 views

SED and REGEX extraction and rejecting if pattern not found

In the SED command, I want to remove everything that comes after 2000_SOMENAME also if possible want to give an error if that format is not found. For example, if the file name is ...
user avatar
1 vote
2 answers
43 views

How replace all dots AFTER other chars got captured

I'm trying to rename some shows with the perl-rename command. The format currently looks something like this: series.S01E**.title.of.the.episode.mkv The asterisks are place holders for the episode ...
user avatar
  • 15
1 vote
1 answer
36 views

Unexpected appended output from sed [closed]

I am trying to edit a couple of text files in Newick format. For the purpose of this, there is a species name (which I want to keep) connected by an underscore to a gene name (which I want to remove). ...
user avatar
  • 187
-2 votes
1 answer
104 views

Unable to understand what the sed commands are doing in this script

I have a script with a function which is sourced in other scripts. I am trying to go line by line but the sed regex is too complicated. #!/usr/bin/env bash # This function will update the value ...
user avatar
  • 323
3 votes
1 answer
121 views

Extracting specific files from a jar using regex

I have a config jar that contains files like below in its resources directory. The names are in the format <text>-<text>.properties or <text>-<text>-<alphanumeric>....
user avatar
2 votes
8 answers
879 views

Get the last word on each line

I have a large text file generated from strace which contains in brief % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- ...
user avatar
  • 43
0 votes
0 answers
31 views

rename files based on keyword

i need help in renaming files: $ cat q.txt Only in /aa/bb/home/sh/POC/Backup/DDL/: comp1.txt Only in /aa/bb/home/sh/POC/Backup/DDL/: comp.txt Only in /aa/bb/home/sh/POC/Backup/DDL/: junk.txt Files /aa/...
user avatar
  • 13
-1 votes
1 answer
31 views

bash + verify if file that ended with many combinations exists [duplicate]

we can have the /tmp/file.1 or /tmp/file.43.434 or /tmp/file-hegfegf , and so on so how we can verify in bash if any /tmp/file* exists ? we try as [[ -f "/tmp/file*" ]] && echo "...
user avatar
  • 11.1k
0 votes
1 answer
39 views

sed - group does not match when including bracket

hoge.txt tsar@gmail.com c2m_@hotmail.com.es c72@hotmail.com.es.com;es m7_@hotmail.es.com cm_@hotmail.com @pepito.com Without group, extract email works. $ cat hoge.txt | sed -nr '/[^@]+@[^.]+\.com$/...
user avatar
  • 181
0 votes
2 answers
43 views

Remove extra characters from diff output

I have the below output from unix: $ diff -y --suppress-common-lines backup.txt newfile.txt > `jjj' int, i need only jjj : int as ...
user avatar
  • 13
2 votes
2 answers
286 views

Need assistance with writing a bash script that uses regex to validate that password input meets length and special character requirements

I have been working on this for a while, visiting dozens of sites and trying all kinds of combinations; however, I cannot get the script to run as intended. Even when they work in https://regex101....
user avatar
0 votes
2 answers
30 views

Rename files to order them using perl substitution

I have a set of files like the following fine_0.vtu fine_10.vtu fine_4032.vtu ... I want to add padding 0s to be able to order them and render them I am trying this command rename -n 's/fine_(\d+)....
user avatar
  • 231
1 vote
2 answers
79 views

How to match all lines sharing same words

I'm using integrated search feature with in Visual Studio Code. In search criteria there is regEx way of searching things. I'm trying to search complete CSV (using Visual Studio Code IDE), exact match ...
user avatar
0 votes
1 answer
23 views

Not obtaining lazy evaluation using sed

I would have expected 'a' for this, why 'a:b'? $ echo "a:b:c" | sed -E 's/(.+?):.+/\1/' a:b
user avatar
  • 481
0 votes
0 answers
41 views

change the bash output with stream editing [duplicate]

If I call bash like this: bash|sed 's/a/b/g' every time bash outputs an 'a' it is replaced with a 'b' $ bash|sed 's/a/b/g' $ echo aaa bbb $ exit However if I add additional substitutions like so: ...
user avatar
-1 votes
1 answer
72 views

-bash: syntax error near unexpected token `(' when using lookahead and lookback?

The use case is rather simple. I have a text file, say the following named eg.txt: 'simple_example': 345, 'to_demonstrate': 232, 'regex': 'is not easy to use' I am trying to capture the keys: grep -...
user avatar
  • 101
0 votes
0 answers
30 views

end anchor in regex with grep not working [duplicate]

I am attempting to list files that don't end in gz I have a minimal working example: ll chrX_PAR1.phased.vcf.gz | grep -v gz$ should show empty, but the file still shows, with or without quotes. I ...
user avatar
  • 107
0 votes
2 answers
84 views

Rookie Question: Regex in ZSH Script

I think my problem is very simple. I want to construct a new filename, which has a fixed prefix and a number (two digits), which is part of the old filename. Example: I have a file 'blableblub23.pdf' ...
user avatar
  • 1
0 votes
1 answer
71 views

Return content between corresponding brackets

I have a file with all type of brackets {}[]()- nested, open and close appropriately. I would like to return the content within the matching square brackets after the string (text:). The content of ...
user avatar
  • 7
0 votes
1 answer
38 views

sscanf equivalent in shell script

I have a file which has some stats and counters stored for some ACL rules. I want to design a shell script to read that file and parse those counters. I have done the similar thing in c programming ...
user avatar
  • 131
1 vote
2 answers
88 views

How to search filenames by regex with "find" and rename this files

I trying to find all files ending with : ancestors-the-humankind-odyssey-trailers-720-1262.mp4 high-tech-divers-1080-1234.mp4 amazon-divers-720-1323.mp4 and rename this files like this : 720-1262....
user avatar
0 votes
0 answers
46 views

expect script regular expression not working

In expect script I am trying to capture some text from output Text in output is like ivalue=16ef7baa-0de1-48bf-9e04-d486defbee1c, code: expect -re {^(ivalue)\=(.*)(\,)$} puts "expect_out (0, ...
user avatar
0 votes
1 answer
27 views

How to recursively change names of files to match?

I'm trying to change the names of multiple files recursively within a directory, looking something like this: parentdirectory/dir1/foo_1.txt /dir2/bar_1.txt /dir3/foo_2....
user avatar
0 votes
1 answer
56 views

I'm trying to understand how to shorten regex

I'm trying to list all directories that are 1GB or larger. I know I could use ncdu, but at the moment, I'm just trying to understand how to shorten regex... I found this command, du -h . | grep '[0-9\....
user avatar
0 votes
2 answers
22 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. ...
user avatar
  • 960
1 vote
1 answer
67 views

How to get the matched expression in GNU Recutils?

In the GNU Recutils manual, it is written that The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to sub-expressions within ...
user avatar
  • 71
0 votes
0 answers
35 views

Rename command in Ubuntu: change character after date only when date at the beginning of the filename

For example this example with a date (my dates change, but they have always the format YYYY-MM-DD) and a trailing -: 2022-04-28-examplename-some-more-text-2022-04-28-more-text.txt should become the ...
user avatar
  • 1
0 votes
2 answers
115 views

Using a regex search with sed to sort entries in a file

I have a text file of the following form: dir1/sub-dir1/.../filename1 author date dir1/sub-dir1/.../filename2 author date . . . dir2/sub-di2/.../filename1 author date dir2/sub-dir2/.../filename2 ...
user avatar
  • 101
3 votes
1 answer
288 views

ignore whitespace at the beginning of a search pattern

This sed expression works, but is there a better way to represent the white space in both the search pattern and replace string? BRANCHTAG=7.17.9-main-5ee3e99d5ff002862d93728d821461033de1186d ...
user avatar
0 votes
0 answers
70 views

Get a PulseAudio Sink Input based on application.process.binary

The command pactl list sink-inputs will print a list of all sink inputs, each one contains a series of properties and some will have the application executable under a property called application....
user avatar
  • 101
0 votes
2 answers
130 views

How to quantify POSIX extended regex?

Password should start with a capital (uppercase) letter Password should contain a lower-case letter Password should contain a number Password length should be a minimum of 8 and less than 16 ...
user avatar
  • 323
0 votes
1 answer
40 views

How does the regular expression [\\\/][^\\\/]*$ work?

I've some notes of useful regular expressions and one that I always use is the following: echo '/home/user/folder/file.txt' | sed -E 's/[\\\/][^\\\/]*$//g' The result that I get from this regular ...
user avatar
  • 319
3 votes
3 answers
488 views

How to to suppress error in bash script

I am trying to suppress error generated by date command but still error is coming post executing script. #!/usr/bin/bash input="30 FEB 2022" reg="^[0-9]{1,2}\s[a-zA-Z]{1,3}\s[0-9]{1,4}$...
user avatar
  • 91
2 votes
2 answers
518 views

Bash : `[0-9]+$` Regular Expression is not working to match exclusively 3-digit numbers

I have executed below code to check if field "eid" is having length 3 digit and all are digit - #!/usr/bin/bash input="A01#PoonamSahani#IVS#123456" #recCount=`echo $input | awk -...
user avatar
  • 91
0 votes
1 answer
86 views

Why can't I match ] with sed

I'm trying to match either [ or ] in a character set in sed but for some reason it doesn't like ] $ echo 'foo [bar]' | sed -E 's/[\[\]]//g' foo [bar] The following works: $ echo 'foo [bar]' | sed -E '...
user avatar
  • 33.3k
0 votes
1 answer
41 views

String searching with grep [duplicate]

I'm just searching in emacs some strings with following pattern: ^*DEFUN*event*$ So i've used grep: grep -nR "^*DEFUN*event*$" * but got no match, instead there's a lot of them for example:...
user avatar
-4 votes
1 answer
81 views

SED - Create new line if finds ONE or ANOTHER MATCH

I have some files in a folder Each file has this structure: ... infos: '{"NAME":"Product","CLASSES":[255,107,255,108,255,255,0,0,255,255,255,255,255],"ISSALE":0,...
user avatar
-1 votes
2 answers
60 views

SED - Generate line only if match some words in OTHER LINE [duplicate]

Assume I have 2 files in a folder ... product: Nike New Awesome Running Shoe price: 123 color: black ... ... product: Nike New Awesome Salloon Soccer Shoe price: 123 color: black ... I need to ...
user avatar
-1 votes
5 answers
87 views

SED - Generate line using some content of other line

I have some files in a folder Each file has this structure: ... product: Nike New Awesome Shoe price: 123 color: black ... I need to accomplish bellow scenario using single SED command, in all files ...
user avatar
-1 votes
1 answer
37 views

need help with a RegEX to match comments with no unicode chrarchters there [closed]

so here is my example #match #match #match foobar#not-matched the regex I was using was \s?\# but this ended up matching $# in my bash script which I don't want it to do that or a regex which ...
user avatar

1
2 3 4 5
52