Weird grep corner case? [closed] - regex

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
If I have a file named 'test' with text literally:
\<.abc\>
and then run grep -E 'abc\> | [1-5]' test, I get no results as expected,
but when I run just grep -E 'abc\>' test, I get a match!
Why is this?
It looks like this problem was solved, but one other follow-up question:
If I wanted to use a regex like 'abc>' and for there to be no results (because no word ends with abc), how can I do this? (I also want to keep the quotes so that I can expand the regex).

grep -E 'abc\> | [1-5]' test, I get no results as expected
because you added spaces before and after the |, try:
grep -E 'abc\>|[1-5]' test
test here:
kent$ grep -E 'abc\>|[1-5]' <<<'\<.abc\>'
\<.abc\>

Related

List files starting with two different prefixes - linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I have files:
list-a1.jpg, list-a2.jpg
list-b1.jpg, list-b2.jpg
map-a1.jpg,map-a2.jpg
map-b1.jpg, map-b2.jpg
I want to list them using ls. I want to use regex but I have problem with prefixes. How to specify that my filename should start with "list-" or "map-"?
I tried to do:
ls [.map-.][.list-.][a-b][1-2].jpg
but it is not working as expected.
ls accepts multiple file parameters: ls [OPTION]... [FILE]...:
ls list-* map-*
For more control, you could take advantage of bash's curly brace expansion:
ls {list,map}-{a,b}{1,2}.*
You could use "extended globbing" - documentation:
shopt -s extglob
ls #(map|list)*

shell script find and replace in regex linux [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
The community reviewed whether to reopen this question 3 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I'm trying to use
sed -i -e "s/.*seb.*/ \"$ftp_login_template\"/" $ftp_dir
however I get this error:
sed: -e expression #1, char 34: unknown option to `s'
I don't understand why since this works perfectly:
sed -i -e "s/.*wbspassword.*/ \"wbspassword\": \"$password\",/" $user_conf
Any ideas as to what I'm doing wrong?
Could this be the problem?
ftp_login_template=\${user}:${password}:24:86::\/var\/lib\/clit.${user}\/downloads:\/bin\/false\"
The problem is with slashes: your variable contains them and the final command will be something like sed "s/string/path/to/something/g", containing way too many slashes.
Since sed can take any char as delimiter (without having to declare the new delimiter), you can try using another one that doesn't appear in your replacement string:
replacement="/my/path"
sed --expression "s#pattern#$replacement#"
Note that this is not bullet proof: if the replacement string later contains # it will break for the same reason, and any backslash sequences like \1 will still be interpreted according to sed rules. Using | as a delimiter is also a nice option as it is similar in readability to /.

Copy files that have pattern in this directory and change name of file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
Suppose I have these files in a directory
/var/mydir/web.php
/var/mydir/dbMuseum.php.example
/var/mydir/dbStreet.php.example
In Ubuntu Linux, what would be a one line command which would copy and rename all the files to the same names but without .example on the end?..giving the correct result:
/var/mydir/web.php
/var/mydir/dbMuseum.php.example
/var/mydir/dbMuseum.php
/var/mydir/dbStreet.php.example
/var/mydir/dbStreet.php
Just a bash for construct with parameter expansion would do:
for f in *.example; do mv -i "$f" "${f%.*}"; done
Ubuntu has rename (prename):
rename -n 's/\.[^.]+$//' *.example
-n would do the dry-run, remove -n for actual renaming to take place:
rename 's/\.[^.]+$//' *.example

Notepad++ regular expression [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
{\i that}
and,
{\i it is this}
I cannot find the way to delete extra stuff from expressions so as to keep only at the above example the words "that" and "it is this".
Can you help me with the regular expression needed?
Try each of the following two expressions (the first one is more efficient if the text between { and } can't contain a } symbol):
\{\\i ([^}]+)\}
Or,
\{\\i (.+?)\}
and in both cases replace with \1.
echo "{\i it is this}" | sed 's/{\\i //;s/}//'
Search : \{\\i (.+)\}
Replace with : \1

Scripts: how to remove hex strings in a text file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
The input file is like
<org.eclipse.core.runtime.adaptor.EclipseClassLoader#1c7d9114,Lorg/eclipse/core/
resources/ResourcesPlugin;>.<init>(Lorg/eclipse/core/runtime/IPluginDescriptor;)V
the goal is to remove hex strings like 1c7d9114,.
The length of the hex strings is fixed, that is 8.
please also include the immediate following comma.
Is there any simple script could deal with this?
Using sed:
sed 's/#[a-f0-9]\{8\},/#/' input
Using perl:
perl -pe 's/\#[a-f0-9]{8},/\#/' input.txt
Using awk:
awk '{gsub(/#[a-f0-9]{8},/,"#",$0)}1' input.txt