Replace in all in all folder - replace

I have the same problem that here :
replacing a complex pattern using sed
I have tried the solution but :
the file is not saved
It's only for one file (I want to apply to all files in all folders)
Thanks for your help.

This works perfectly :
http://www.garzul.tonsite.biz/wordpress/2016/07/20/how-to-remove-malicious-code-infecting-every-php-files-of-a-website/
Thanks to author.

Related

Regex Assistance for replacing filepaths in markdown documents

I migrated my notes from evernote to markdown files with yarle. unfortunately it created me a lot of folders seperatively for the attachments (although I set it up for one folder only).
I moved all attachements to one folder, so the filepath to the attachments in the mardown files needs to be updated.
I think regex would be right for this, but I don't have any knowledge about regex and would be really thankful for help.
Filepaths are as follows:![[./_attachmentsMove/Coordination_Patterns.resources/CoordinationPattern_Ipsi.MOV]]
All filepaths are identical ![[./_attachmentsMove/]] up to this
The second folder varies e.g. Coordination_Patterns.resources/.
I want to delete everything but the filename.extension itself e.g. ![[CoordinationPattern_Ipsi.MOV]].
An example of the other filepaths:
![[./_attachmentsMove/Jonglieren_(Hände).resources/07 Jonglieren.MOV]]
(second folder changes, filename changes, I also have .png and .mov).
I use MassReplaceIt (app for mac) which allows me to replace expressions in documents with regex. If someone has a solution using the terminal/commandline, I'll try this as well of course :)
Try if this regexp suffices:
(?<=!\[\[)[^\]]+/(?=[^\]/]+]])
Replace with empty string.
It should delete the part from the ![[ up to the last / before the next ]].

Rename everything before brackets for files

So I have a bunch of files who go like this : Yu-Gi-Oh! Zexal - Magic (S01E40).mp4 and I try to rename all of my files like this : S01E40 , I tried this command :
rename 'y/(\((?>[^)(]+|\g<1>)*\))//' *.mp4
Nothing changed .
Anyone can help me ?
Use
rename 's/.*\((.*)\).*(\.mp4)$/$1$2/' *.mp4
It will only keep what is in last parentheses and the extension.
y/// is the same as tr///, i.e. transliteration, which exchanges characters one by one. s/// is for substitution.

How to replace extension in bash regex?

I'm trying to write a bash script to calculate some biological stuff. I have a problem with regex, bash is a little unfamiliar to me yet. Unfortenly I have no time to learn it that fast coz I need immanently results.
So my files:
RV30.afa
resFilesRV30.fasta
RV30213.afa
resFilesRV30213.fasta
RV30441.afa
resFilesRV30441.fasta
...
Command i have to use:
mscore -cftit RV30.afa resFilesRV30.fasta >FinalRV30.txt'
What i have now:
#!/bin/bash
parallel 'mscore -cftit {} resFile{}.fasta >final{.}.txt' ::: RV*.afa
The problem is:
resFile{}.fasta = is trying to open file like this: resFileXXX.afa.fasta i need to skip extension in second argument (.afa) and ovewritte it by ".fasta".
I didn't find a piece of good advice on google for my problem (or i can't reforge it to my script yet), and my time to get results already ends. So i will be grateful for help in solving this problem. On its basis, I will be able to solve some of the others that appeared in my other scripts
This should work for you by substituting {} with {.} in 2nd argument:
parallel 'mscore -cftit {} resFiles{.}.fasta >final{.}.txt' ::: RV*.afa
As you're using already in your command, the replacement string {.} removes the extension.
Does this not work?
for afafile in *.afa; do number="${afafile#file}"; number="${number%.afa}"; ./mscore -cftit "$afafile" "resFile${number}.fasta" > "file${number}final.txt"; done

Using regexp in a windows bat file with BRC32 renaming utility

I am using Windows XP and wrote a simple bat file that goes out and downloads XML from a website then it renames the xml files so they all have a .zip extension but for some reason it won't rename the files. Here is the line of code that doesn't work using BRC32, it seems to have trouble doing a REGEXP in windows.
.\software\BRC32 /DIR: /REGEXP:.*%22(.*)%22:\1.zip /EXECUTE
File Name: download#down_stds=all&down_typ=results&cond=%22Aicardi Syndrome%22
Desired result: download#down_stds=all&down_typ=results&cond=%22Aicardi Syndrome%.zip
I am using the BRC32.exe utility that also uses the pcre.dll version 3.9 to do the REGEXP in the bat file, but for some reason I just get an error that says the file could not be renamed. Does anyone have any insight into this problem>?
Changing '%' to '%%' in the script fixed my problem
Since you don't say what BRC32' syntax is, I'd make a guess at the /REGEXP:.*%22(.*)%22:\1.zip part.
If the parser doesn't object to %22(,*)% it's likely to be resolved to [nothing].
If you really want to poke % as a parameter-character, then try doubling the %s since % escapes %.
But also, 22 look ssuspiciously like a " to me. Possibly you could replace the %22 with " - but without knowing exactly what the parameter means, it's hard to advise.
But ."(.*)"\1.zip looks very strange too...
yep. adding another % sign fixed it. damn I feel so stupid

Ignoring everything but a subfolder in Mercurial

I want to ignore everything BUT a subfolder in Mercurial.
The folder I want to keep:
a/b/c/d/e/f
Everything else under:
a/b
Should be ignored.
I'm using regexp mode in the .hgignore file. This is what I've so far:
a/b/(?!c)
a/b/c/(?!d)
a/b/c/d/(?!e)
a/b/c/d/e/(?!f)
Even if this works fine, I would like to shrink it to a single line:
a/b/(?!c/d/e/f)
Except this doesn't work. I tried to escape the slashes in several ways, but it didn't help.
Any hint?
have you tried this:
a/b/(?!c).*
You probably know this already, but you can just add the stuff in a/b/c/d/e/f without adding an exception to the .hgignore. It's not perfect, you have to remember to add any new files, but I thought I'd mention it since it's non-obvious to we CVS/SVN refugees.
^a/b/(?!c/d/e/f).*$
Why not just create the hg repo in a/b/c/d/e/f?