Questions tagged [regular-expression]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
10 views

imagemagic: convert +append images : pass the list of files in numeric order rather than alphabetical order [duplicate]

I am trying to join few images into one single image These are the list of files i have to join them horizontally slice_0_0.png slice_0_2.png slice_0_4.png slice_0_6.png slice_0_8.png slice_0_10.png ...
-2
votes
1answer
28 views

Apending text to end of file

I am using sed to add text to end of file. So far I have tried a. sed -i -e '$ a mynewtext' filename b. sed -e '$amynewtext' filename My file looks like this 90577958 90399451 90219954 90089937 ...
0
votes
1answer
20 views

How to Search XML Block and Delete the same

This is my XML. <configGroup> <type>SERVER_CONFIG</type> <configProperty id="Server48"> <configProperty> <name>Server Name</name> <...
0
votes
0answers
22 views

Regex search in PDF reader

I am a happy zathura user since I enjoy its minimalist approach, but to be clear I would also switch to mupdf or anything else if this would solve my problem. I need to highlight every word from start ...
1
vote
2answers
37 views

Gnu Sed (on Gnu/Linux) to find match + “anything” and replacing it

I'm trying to use sed to find matching string on a line in a file on nth match. I want to use expression to mach num and "anything" after on that line and replace it with num x. example file: START ...
0
votes
2answers
24 views

Questions about regular expression matching results

I executed the following command ip addr | grep -En 'inet (([0-9]*\.){3}[0-9]*)/24' | awk '{print "LAN:" $3 }' why the result is '192.168.123.245/24', instead of this192.168.123.245? Another ...
1
vote
3answers
26 views

Shell script, get/extract mac address from console output of command after “MAC: ”

I'm trying to automatically pull out the mac address of a arduino device using a shell script, and need some help how to do this. This is the output returned by the command: Opening /dev/cu....
-2
votes
1answer
56 views

How to match x number of characters of a file name with cp?

I try to use cp to copy a file with a partially dynamic name: cp google71bg2z2850dafxa3.html DESTIONATION By principle, the google part of the file name is consistent, but the 71bg2z2850dafxa3 (16 ...
0
votes
1answer
21 views

egrep regex: having [ and ] or dot in character class does not match

I am trying to match an IPv6 address with square brackets but I am surprisingly stuck... Works: echo 'files ([2001:450:671d:200::121]:59464).' | egrep 'files \(.+\)\.$' Does NOT match (but I think ...
0
votes
0answers
30 views

Use a regex pattern to search a file and count occurances

I am trying to search the DNS Bind querylog file ( domain requests for DNS) on Linux (raspberry pi) with a pattern to pull out the domains and then tally up the occurances of each domain The ...
0
votes
3answers
47 views

awk and egrep for regular expression

I am very new to unix! trying to figure out, from a fastq file how many reads have 3 or MORE As in a row? I used egrep 'A{3}' to tell me how many AAA I have. But now I want to know >= 3 AAA in a ...
0
votes
1answer
31 views

regex (or other way) to find numbers followed by a space

I'm running the following awk '$2 ~ /^[0-9]\s+/ {print($2)}' file >> file1 Not sure how to correct this to only select lines where digits are followed by a space?
0
votes
1answer
32 views

Regex in Bash for Git Push Output

Working on a simple script to backup some IDE settings and to learn bash scripting. Here is what I have so far: #!/bin/bash NEWLINE=$'\n' pushRegex='^([0-z]{7}[\.]{2}[0-z]{7}\s{2})(\w+)\s{1}(->)\...
0
votes
2answers
35 views

Append text to flagged output of awk

I have a function that takes a filename. It then runs a command and filters the output (exclusive) between two patterns, then it outputs comma separated values with the filename output of the command. ...
0
votes
1answer
46 views

How to add text after the nth occurrence in bash?

Let's say I have helloworld.txt: hello world Using sed: sed 's/w*/goodbye/' helloworld.txt Gives me: goodbyehello world And: sed 's/$/goodbye/' helloworld.txt Gives me: hello worldgoodbye ...
0
votes
1answer
22 views

Vim is inserting ^@ when I try to insert a line break

When I open Vim on my laptop and run regex like this: :%s/foo/\n/g vim inserts ^@ instead of line breaks. This problem started happening last week. I'm running Ubuntu 18.04.04. I think the problem ...
0
votes
1answer
26 views

What is the bash code to remove varying characters in a file name up to a certain point?

I have a set of files that vary in characters. For Example: IDNR19_15_037_S514_L001_R1_001.fastq IDNR19_02_016_S238_L001_R1_001.fastq I would like to remove all of the characters up the point of ...
0
votes
2answers
50 views

regex to group them same name

I have following lines in foo.txt aaa:6600 location: US aaa:6622 location: US xxx:6601 location: EU xxx:6602 location: EU xxx:6603 location: EU ggg:7701 location: KR ggg:8808 location: KR I ...
3
votes
4answers
141 views

sed: Remove everything from dot after FQDN

I am new to sed and am having some troubles making it work. What I want is this: abc.ztx.com. A 132.123.12.44 ---> abc.ztx.com I used the below pattern, but doesn't seem to work: echo "abc.ztx....
0
votes
1answer
32 views

Regex within awk from txt file with one line

I am currently working on a script to wipe hard drives. The first script is already working and checks if there are new hard drives available. If there is a new disk available it will list it in a ...
0
votes
1answer
28 views

Find files with specific character in second position in name

How can I find files with this pattern like ??11* or ??52*, start with two unknown numbers and two specific numbers and other nothing matter. 972966220_56_2_1_L2_P.jpg 971051472_69_2_1_L2_P.jpg ...
0
votes
0answers
33 views

extract text between the 7th and 8th “/” characters

I have about 100,000 variables with a full path to the location of a relevant file. The form is like this: /abc/def/ghij/klm/nopq/r/stu/vwx/yz The string I am looking for is the one between the 7th ...
0
votes
1answer
35 views

sed swallows braces / curly brackets

I've got a LaTeX file containing \newcommand{\revision}{value} And during CI I want to do the following: REV=${CI_COMMIT_TAG:-$CI_COMMIT_SHORT_SHA} sed -i 's/{\\revision}{\(\w*\)}/\1'"$REV"'/' ...
0
votes
0answers
32 views

sed doesn't consider a second match if it overlaps with the first match in the string

The title may be confusing, so here is an example: $ echo X012X | sed 's|[0-1][1-2]|AA|' XAA2X $ echo X012X | sed 's|[0-1][1-2]|AA|2' X012X The first output is trivial, but not the second. Reading ...
-1
votes
2answers
47 views

how to extract string by Regex with grep?

say I have a SQL.txt select * from table1; select a,b,c from table2 where a=1; How can I filter the table name with the command cat SQL.txt|grep My expected output is: table1 table2 I'm a newbie ...
0
votes
2answers
53 views

How to negate regex using test

This is syntactically wrong: #!/usr/bin/env bash dimension="4x5" if [[ "$dimension" !=~ '[0-9]x[0-9]' ]]; then echo 'wtf meng, the dimension needs an "x" in it.' return 1; fi the above has bad ...
2
votes
2answers
62 views

Vim - How to replace a newline with the string “\n”

In vim, I want to replace newlines with the literal string \n. For example, if I open a file that contains this text: This is line one This is line two I want to replace the newlines and have the ...
0
votes
3answers
39 views

Bash: delete curly braces on a condition

I want to remove curly braces from the string below, but only if * is found between them. I have found a lot of answers on this topic, but in my scenario I want to delete only those braces where ...
3
votes
5answers
1k views

if with regex in bash code

In bash I did the following. This if expression will evaluate to true if the Redhat version is 7.5 or 7.6. if [[ ` cat /etc/redhat-release | awk '{print $7}' ` == "7.5" ]] || [[ ` cat /etc/redhat-...
2
votes
1answer
41 views

String removal inside xargs printf statement?

Currently my mbsync is erroring out with a bunch of duplicated UIDs. This means I have to find all files that have duplicates of the sub-string "U=[0-9]+:" and change the most recent file to remove ...
1
vote
2answers
33 views

Adding a suffix to a matched regular expression does not work

This is the list of numbers i have: 46066.874.89 48569.123.56 56489.256.88 654.12.32 84689.25.69 My goal is to add two zeroes at the end of 654.12.32. But for some reason neither sed -E 's/(\.[0-9][...
0
votes
0answers
55 views

AllowGroups in the /etc/ssh/sshd_config file

The following sed command adds my_unix_admins to the end of the lines starting with the word AllowGroups. /bin/sed -i '/^AllowGroups / s/$/ my_unix_admins/' /etc/ssh/sshd_config I want to only add ...
2
votes
2answers
52 views

Add a suffix to a matched regular expression

I got some lines containing numbers in the first field: 46066.874.89 48569.123.56 56489.256.88 654.12.32 84689.25.69 What I would like to do now is add 00 at the end of 654 in the fourth line and ...
0
votes
0answers
26 views

how to replace and delete symbols in a single SED command [duplicate]

Currently I'm replacing symbols A and B and deleting symbol C with two distinct sed commands in a pipe: % cat file.txt | sed 's/, /;/g' | sed 's[][]//g' Is there a way to have these two in one sed ...
-1
votes
1answer
49 views

I would like to export below data into csv file from the multiple property files; files are not in the standard format [closed]

Filename: hello1 cassandraDriver.contactPoints=10.65.4.203,10.65.4.220 cassandraDriver.port=9042 Filename: hello2 cassandraDriver.contactPoints=10.65.4.203 cassandraDriver.port=80 onprem.cassandra....
0
votes
2answers
43 views

need help with SED to omit some expressions

sed -E 's/([0-9]{3})-([0-9]{2})-([0-9]{4})/ /g' a.dat > b.dat This is replacing 111-11-1111 to spaces , but its also replacing 0111-11-1111 to spaces to... But I want it to ignore 0111-11-1111 (...
-1
votes
2answers
21 views

filename globbing

I would like to know why these 2 filenames globbing expression [bru][abru]* and [br]* will return me a filename call brutus but will not return me this filename abruti thanks
1
vote
1answer
21 views

regular expression

I'm not sure about the meaning of this regular expression. ^[^a]*$ Does that mean, we don't want any string started with the letter a or contain a. And we don't want any string ended with also the ...
0
votes
2answers
67 views

sed add first word from previous line to beginning of the next line, if

I ran into a problem and can't find a solution to fix the following issue. I want to copy the first word of a line to the beginning of the following n lines if they start with a special character, ...
1
vote
2answers
45 views

Does order in sed's regex character classes (e.g. [abc]) matter?

I guess it's best to start with an example: > echo "[20-20:10]Something" | sed -r -e 's/^\[[0-9\:\-]+(.*)$/\1/' ]Something > echo "[20-20:10]Something" | sed -r -e 's/^\[[0-9\-\:]+(.*)$/\1/' -...
-1
votes
1answer
40 views

Match system path with awk in if statement

I am trying to catch if the file system was mounted on a directory tree with: mount | awk '{ if ( $3 == /mnt/pxe ) print mounted }' But the string is not catched even though mount exists. The mount ...
0
votes
1answer
52 views

SED find and replace internal filepaths from files

we have few asset files with internal filepaths, for example "/Users/testuser/dev/app-path/widget" such as below. test.js [["elliptic@6.5.2","/Users/testuser/dev/app-path/widget"]],"_development":...
0
votes
1answer
54 views

Replace (remove) multiple lines from files

A server of mine was hacked, and they added at the beginning of every js file the following: var hglgfdrr4634hezfdg = 1; var d=document;var s=d.createElement('script'); s.type='text/javascript'; s....
0
votes
3answers
49 views

Removing everything after pattern with sed or awk

I know there are lots of questions about it but I can't get it working. I want to clean a group (for instance root) in /etc/group with sed or awk. So I need to delete everything after root:*:0: I ...
0
votes
1answer
24 views

Print text after pattern from one file in another file on mac OS X

The script below looks at printing any text after the first occurrence of pattern "Word1 word2" from file1.txt in another file called newfile.txt: sed -n -e 's/^.*Word1 word2/\1/p' file1.txt > ...
2
votes
5answers
91 views

How can I match all characters up to the second to last white space character in a string?

I'm trying to replace the substring "Abbey Street E.2 " in the string "Abbey Street E.2 Buckfast Street" to get the result "Buckfast Street". I tried :s/[^ ]* [^ ]* //but I'm getting "Street". ...
0
votes
2answers
57 views

sed regex not working in shell script

Given: ~$ cat .test-profile export ADMIN_EMAIL=info@mail.com export MONGODB_URI='mongodb+srv://administrator:abcdef@mysite-cluster-n1qub.mongodb.net/test?retryWrites=true&w=majority' I wrote the ...
1
vote
3answers
89 views

How to replace a line in text using RegEX?

The problem I have is that is trying to match both sets of delimiter (above and below) I'm trying to match only the second part of the delimiter below (bolded). This is so I can add a new version ...
0
votes
1answer
40 views

Find Duplicate/Repeated or Unique words spanning across multiple lines in a file

Problem Is it possible to print repeated words that are not unique and spanning across multiple lines? not just unique words within singular lines. Previous work There's this question which solves ...
1
vote
2answers
184 views

grep regular expression that matches all valid IPv4 and IPv6 addresses

I'm looking for a regular expression for grep that filters out IPv4 and IPv6 addresses from an arbitrary file containing them. I'd like it to behave like this one for IPv4 addresses: grep -E -o "(25[...

1
2 3 4 5
42