Bash, need to change word order in multiple directories - regex

I have a considerable classical FLAC collection where each album is a directory. I've realized that I have used a sub-optimal structure and need to rename all the directories.
My current naming convention is:
COMPOSER (CONDUCTOR) - NAME OF PIECE
E.g.
"Bach (Celibidache) - Mass in F minor"
I want to change the naming to
COMPOSER - NAME OF PIECE (CONDUCTOR)
I.e.
"Bach - Mass in F minor (Celibidache)"
There are some possible exceptions, the (CONDUCTOR) may be (CONDUCTOR, SOLOIST) and some directories do not have the (CONDUCTOR) part and should be left as is. The NAME OF PIECE can contain all legal letters and symbols.
All albums are located in the same parent directory, so no sub-directories.
What is the easy way to do this?

use perl rename (some distributions have this as rename - Ubuntu and related, some as prename - Fedora and Redhat AFAIK). Check first.
prename -n -- '-d && s/(\(.*\)) - (.*)/- \2 \1/' *
-n don't rename just print the results - remove after you are ok with the results.
-- end of the options, start of the perlexpr and files
-d check that the file is a directory
s/.../.../ - substitution
Example:
[test01#localhost composers]$ ls -la
total 12
drwxrwxr-x 3 test01 test01 4096 Feb 14 12:37 .
drwxrwxr-x. 7 test01 test01 4096 Feb 14 12:23 ..
drwxrwxr-x 2 test01 test01 4096 Feb 14 12:37 'Bach (Celibidache) - Mass in F minor'
-rw-rw-r-- 1 test01 test01 0 Feb 14 12:27 'Bach (Celibidache) - Mass in F minor.flac'
[test01#localhost composers]$ prename -n -- '-d && s/(\(.*\)) - (.*)/- \2 \1/' *
Bach (Celibidache) - Mass in F minor -> Bach - Mass in F minor (Celibidache)
[test01#localhost composers]$ prename -- '-d && s/(\(.*\)) - (.*)/- \2 \1/' *
[test01#localhost composers]$ ls -la
total 12
drwxrwxr-x 3 test01 test01 4096 Feb 14 12:38 .
drwxrwxr-x. 7 test01 test01 4096 Feb 14 12:23 ..
-rw-rw-r-- 1 test01 test01 0 Feb 14 12:27 'Bach (Celibidache) - Mass in F minor.flac'
drwxrwxr-x 2 test01 test01 4096 Feb 14 12:37 'Bach - Mass in F minor (Celibidache)'
Note that without -d both the file and the directory would have been renamed.

Related

When attemping to copy a dir from repo to container in workflow, it's as if COPY command did nothing

My repo:
/
dbt-action/
action.yml
Dockerfile
entrypoint.sh
dbt/
profiles.yml
My workflow step:
- name: Run DBT
uses: ./dbt-action
My Dockerfile:
FROM ghcr.io/dbt-labs/dbt-redshift:1.3.latest
COPY dbt .dbt
COPY entrypoint.sh /entrypoint.sh
My entrypoint:
!/bin/bash
pwd
ls -la
Outputs the following:
drwxr-xr-x 6 1001 123 4096 Jan 7 13:06 .
drwxr-xr-x 6 root root 4096 Jan 7 13:06 ..
drwxr-xr-x 8 1001 123 4096 Jan 7 13:06 .git
drwxr-xr-x 3 1001 123 4096 Jan 7 13:06 .github
drwxr-xr-x 3 1001 123 4096 Jan 7 13:06 blah
-rw-r--r-- 1 1001 123 1744 Jan 7 13:06 README.md
drwxr-xr-x 3 1001 123 4096 Jan 7 13:06 dbt-action
Expected output:
Same as above but with additional directory .dbt coming from COPY dbt .dbt in my Dockerfile.
Why don't I see dir .dbt when I ls -la in my entrypoint?
Seems like you are executing your ‘Docker build’ from the wrong working directory, since the ‘dbt-action’ folder is present, but not it contents. Can you double check the PWD before you build?

Privileges problem UMASK Nautilus. CentOS 7.7

I have a problem with the privileges of [files/folders] created by Nautilus. As a test I set the UMASK of my specific user to 0000:
[simone#MYPC:~] >cat /mnt/home/simone/.bashrc | grep mask
# User Umask Override
umask 0000
[simone#MYPC:~] >cat /mnt/home/simone/.bashrc
# $HOME/.bashrc
umask 0000
[simone#MYPC:~] >umask
000
When I write a file or folder passing from terminal I can do it with the required privileges:
[simone#MYPC:~/Desktop] >touch file1.txt
[simone#MYPC:~/Desktop] >mkdir Folder1
[simone#MYPC:~/Desktop] >ls -la
-rw-rw-rw-. 1 simone home 0 Mar 21 2022 file1.txt
drwxrwxrwx. 2 simone home 4096 Mar 21 2022 Folder1
But when I create a file (TextEditor) or folder through Nautilus, I get different privileges:
[simone#MYPC:~] >ls -lart /tmp
drwxr-xr-x. 1 simone home 0 Mar 18 10:04 FolderByNautilus
[simone#MYPC:~] > ls -la /tmp/fileNautilus.txt
-rw-r--r--. 1 simone home 5 Mar 11 2022 /tmp/fileNautilus.txt
I would like Nautilus or text editor to write with the mask 0000 leaving the same privileges with which my terminal writes

Select specific columns from a record using only 'sed' without using 'awk'

Here are some sample input I obtain from doing ls -l :
-rwxr-xr-x 1 root root 1779 Jan 10 2014 zcmp
-rwxr-xr-x 1 root root 5766 Jan 10 2014 zdiff
-rwxr-xr-x 1 root root 142 Jan 10 2014 zegrep
-rwxr-xr-x 1 root root 142 Jan 10 2014 zfgrep
-rwxr-xr-x 1 root root 2133 Jan 10 2014 zforce
-rwxr-xr-x 1 root root 5940 Jan 10 2014 zgrep
lrwxrwxrwx 1 root root 8 Dec 5 2015 ypdomainname -> hostname
I would like to print out the last column and 5th column using ONLY sed like this:
zcmp 1779
zdiff 5766
zegrep 142
zfgrep 142
zforce 2133
zgrep 5940
ypdomainname -> hostname 8
I'm trying to find a regex to match but have not succeeded. And I'm not allowed to use awk or cut either.
Thank you in advance.
Try this;
ls -l | sed -r 's/^(\S+\s+){5}(\S+\s+){3}/\1/' | sed 's/^\(.*\) \(.*\)$/\2\ \1/g'

Change file extensions in gradle

This seems so simple, yet I cannot find a single source that provides a working solution.
I have a project like this:
src
-main
-resources
-bpmns
-nnn.bpmn
and I want gradle to rename all files that end with bpmn to bpmn20.xml, leaving all files that already have bpmn20.xml extensions untouched.
This is my approach:
task renameBPMN(type: Copy) {
outputs.upToDateWhen { false } //to pevent gradle from not executing this task
from('src/main/resources/bpmn/')
into('src/main/resources/bpmn/')
rename ('/^.*\\.(bpmn)$/', '$1.bpmn20.xml')
}
According to some regex testers online, the regex should match nnn.bpmn, gradle however does nothing at all.
Any ideas anyone?
This is what he needs or actually this script would do it.
Here it'll change a file: filenamebpmn or filename.bpmn to filenamebpmn20.xml or filename.bpmn20.xml respectively. It'll ignore all other files whether it's a filenamebpmn.xml or filename.bpmn.xml or any other file.
$ cat build.gradle
task renameBPMN() << {
fileTree("bpmnfolder").matching { include "*bpmn" }.each { fileName ->
println "Will be changed to new name --- " + fileName
file("${fileName}").renameTo("${fileName}20.xml")
}
}
$ ls -l bpmnfolder
total 3
-rw-r--r-- 1 c400093 Domain Users 3 Aug 6 15:14 1bpmn
-rw-r--r-- 1 c400093 Domain Users 3 Aug 6 14:50 2bpmn
-rw-r--r-- 1 c400093 Domain Users 6 Aug 6 14:50 3bpmn.xml
$ /cygdrive/c/gradle-2.0/bin/gradle renameBPMN
:renameBPMN
Will be changed to new name --- C:\cygwin\home\c400093\giga\goga\giga\bpmnfolder\1bpmn
Will be changed to new name --- C:\cygwin\home\c400093\giga\goga\giga\bpmnfolder\2bpmn
BUILD SUCCESSFUL
Total time: 3.153 secs
$ ls -l bpmnfolder
total 3
-rw-r--r-- 1 c400093 Domain Users 3 Aug 6 15:14 1bpmn20.xml
-rw-r--r-- 1 c400093 Domain Users 3 Aug 6 14:50 2bpmn20.xml
-rw-r--r-- 1 c400093 Domain Users 6 Aug 6 14:50 3bpmn.xml
$
AND
If you want to include filenames which end with bpmn as extension i.e. filename.bpmn or filenamebpmn, then use the following code.
$ ls -l bpmnfolder
total 5
-rw-r--r-- 1 c400093 Domain Users 3 Aug 6 15:39 1bpmn
-rw-r--r-- 1 c400093 Domain Users 3 Aug 6 15:39 2bpmn
-rw-r--r-- 1 c400093 Domain Users 6 Aug 6 15:39 3bpmn.xml
-rw-r--r-- 1 c400093 Domain Users 8 Aug 6 15:39 4.bpmn
-rw-r--r-- 1 c400093 Domain Users 3 Aug 6 15:39 5.bpmn.xml
$ cat build.gradle
task renameBPMN() << {
fileTree("bpmnfolder").matching { include "*bpmn" include "*.bpmn" }.each { fileName ->
println "Will be changed to new name --- " + fileName
file("${fileName}").renameTo("${fileName}20.xml")
}
}
$ /cygdrive/c/gradle-2.0/bin/gradle renameBPMN
:renameBPMN
Will be changed to new name --- C:\cygwin\home\c400093\giga\goga\giga\bpmnfolder\1bpmn
Will be changed to new name --- C:\cygwin\home\c400093\giga\goga\giga\bpmnfolder\2bpmn
Will be changed to new name --- C:\cygwin\home\c400093\giga\goga\giga\bpmnfolder\4.bpmn
BUILD SUCCESSFUL
Total time: 4.271 secs
$ ls -l bpmnfolder
total 5
-rw-r--r-- 1 c400093 Domain Users 3 Aug 6 15:39 1bpmn20.xml
-rw-r--r-- 1 c400093 Domain Users 3 Aug 6 15:39 2bpmn20.xml
-rw-r--r-- 1 c400093 Domain Users 6 Aug 6 15:39 3bpmn.xml
-rw-r--r-- 1 c400093 Domain Users 8 Aug 6 15:39 4.bpmn20.xml
-rw-r--r-- 1 c400093 Domain Users 3 Aug 6 15:39 5.bpmn.xml
$
Modify your task to:
task rename(type: Copy) {
outputs.upToDateWhen { false } //to pevent gradle from not executing this task
from('src/main/resources/bpmn/')
into('src/main/resources/bpmn/')
exclude { resource -> !resource.file.name.endsWith('.bpmn')}
rename '(.*).bpmn', '$1.bpmn20.xml'
}
According to the gradle documentation, AbstractCopyTask::rename()'s regular expression does not need delimiters:
rename '(.*)_OEM_BLUE_(.*)', '$1$2'
Try replacing:
rename ('/^.*\\.(bpmn)$/', '$1.bpmn20.xml')
With:
rename ('^.*\\.(bpmn)$', '$1.bpmn20.xml')

install ocsigen-bundle-2.2.2 error

$./configure --prefix ${HOME}/ocsigen OCSIGEN_USER=${USER} OCSIGEN_GROUP=${USER} --with-missing-libs
...
checking for sqlite3_open in -lsqlite3... no
configure: error: SQLite is required. See the --with-sqlite3 configure option.
$uname -r
[FreeBSD[ 9.0-RELEASE-p3
$whereis sqlite3
sqlite3: /usr/local/bin/sqlite3
$ls -l /usr/local/lib/libsqlite*
-rw-r--r-- 1 root wheel 602092 12 3 2011 /usr/local/lib/libsqlite3.a
-rwxr-xr-x 1 root wheel 943 12 3 2011 /usr/local/lib/libsqlite3.la*
lrwx-rw-r--r-- 1 root wheel 602092 12 3 2011 /usr/local/lib/libsqlite3.a
-rwxr-xr-x 1 root wheel 943 12 3 2011 /usr/local/lib/libsqlite3.la*
lrwxr-xr-x 1 root wheel 15 12 3 2011 /usr/local/lib/libsqlite3.so# -> libsqlite3.so.8
-rwxr-xr-x 1 root wheel 617995 12 3 2011 /usr/local/lib/libsqlite3.so.8*
Any suggestion is appreciated!
I think you can use something like
./configure --with-sqlite3=/usr/local/lib
or maybe just /usr/local to tell the ./configure script that sqlite3 is not in the standard directory (/usr/lib).