List files starting with two different prefixes - linux [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 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)*

Related

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

How to edit filenames in bulk using regex? [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
I don't even know if this is possible.
I have over 4 terabytes of MP3 files and I need a much faster way of editing files. I use a Mac running Yosemite if that makes any difference.
Here is a sample list of files
In bulk, how do I remove the "Elton John", space, hyphen, space, track number, and space from the names of these files, and only leave the track name and file format? Can it be done using terminal and if so, what's the command?
Thanks so much!
brew install rename
rename -v 's/\s*Elton John\s*-\s*\d+\s*-(.*)/$1/' *.mp3
You can use the -n option first to see what would be the changes without affecting the files name.

Rename a set of files based on regular expression [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 8 years ago.
Improve this question
I am looking to rename a large number of files that look like this on my ubuntu box:
MattTest Season 01 Episode 02 - Episode Name.mkv
Would like them to look like this:
MattTest S01E02 - Episode Name.mkv
Thanks
You could try the below rename command. \K keep up the previously matched characters from printing at the final. That is, character which are matched before \K are won't taken into consideration.
rename 's/^\S+\s+\K(.)\S*\s+(\S+)\s+(.)\S*\s+(\S+)/$1$2$3$4/' *.mkv
OR
rename 's/^\S+\s+\K(.)\S*\s+(\d+)\s+(.)\S*\s+(\d+)/$1$2$3$4/' *.mkv
Regex Demo

Weird grep corner case? [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 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\>