Why wildcard character "*.*" can match a file without extension - character

There is a file "a" in a directory. When I search by ".", I get "a".
But the file "a" doesn't have a extension and there is no dot in "a". Why?

Related

How to replace xml string with special character in file

So I have .xml file and I want to replace first xml string which says
<some text="chageThis"> and I want to replace it with <some text="NewText"> and I need to specify path of my file in .sh scrypt. I tried from here
sed 's/file="[^"]*"/file="\<some text="chageThis">/' /path/to/my.xml > /path/to/my.xml
but it does not work

Using PowerShell to replace string that contains + in the string

I am trying to use PowerShell do a simple find and replace. Essentially, I used to have some support files in a directory with the same name of a "master" file. All but one of those support files are no longer necessary. The "master" file has a text reference to the path of the other file. What I want to do is modify this path in the "master" file to remove the deleted directory.
For example, let's say I have the file C:\Temp\this+that.txt I used to have C:\Temp\this+that\this+that.dat that has now been moved to C:\Temp\this+that.dat
C:\Temp\this+that.txt has a line like this:
/temp/this+that/this+that.dat
I would like this line to become:
/temp/this+that.dat
I have lots of these files that a batch file is moving. Everything is working fine using the powershell command below for all file names that do NOT contain a plus + sign. For those files, the call below does not work.
powershell -Command "(gc '!CURRENT_FILE!') -replace '/!BASE_NAME!/', '/' | Set-Content '!CURRENT_FILE!'"
For the example above, CURRENT_FILE would be C:\Temp\this+that.txt and BASE_NAME would be this+that
Can anyone help me with why this isn't working for file names that contain a plus + sign?
#ma_il is exactly right. The '+' character is a special character in RegEx, so you will need to escape it.
powershell -Command "(gc '!CURRENT_FILE!') -replace [regex]::escape('/!BASE_NAME!/'), '/' | Set-Content '!CURRENT_FILE!'"

Cygwin or Gnuwin - Find .txt files named* copy & paste to specific directory

Okay so I want to know how I would go about doing this, using grep to locate .txt files named "cocacola1", "cocacola2", "cocacola3" & then copying them to another directory. So searching for files named "cocacola" &/even if it contains other characters within the file name to then copy them to another directory/location.
You can just use unix find. Assuming the files you're searching for are in 'source' and you want to copy to 'destination':
find source -name '*cocacola*' -exec cp {} destination \;
I put the wildcard '*' before and after cocacola since you said other characters might exist in the file name.

Ignore all files and files in subdirectories except one file

Imagine the following structure:
/a/1.txt
/a/2.txt
/a/.keep
/a/b/1.txt
/a/b/2.txt
/a/b/3.txt
/a/b/.keep
/a/b/c/1.txt
/a/b/c/2.txt
/a/b/c/3.txt
/a/b/c/4.txt
/a/b/c/.keep
/d/test.txt
/d/work.txt
I want to ignore all files in a directory except .keep files to obtain the following results:
/a/.keep
/a/b/.keep
/a/b/c/.keep
/d/test.txt
/d/work.txt
My .gitignore file that doesn't work:
/a/*
!.keep
Unfortunatelly, you cannot reinclude files at directories ignored by previous rules, according to the gitignore Documentation:
It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.
So this
/a/*
!/a/**/.keep
will only reinclude /a/.keep but not the others.
You'll have to exclude each file pattern under /a explictly.
/a/**/*.txt
/a/**/.ignore
/a/**/.alsoignore
UPDATE: Or a better solution is to create the following .gitgnore at your /a subdirectory:
*.*
!.keep
(the only drawback is that this solution will also keep files with no extension)
In your case, you should use:
/a/*
!**/.keep
From the gitignore documentation:
A leading "**" followed by a slash means match in all directories. For
example, "**/foo" matches file or directory "foo" anywhere, the same
as pattern "foo". "**/foo/bar" matches file or directory "bar"
anywhere that is directly under directory "foo".

How can I ignore everything under a folder in Mercurial

I am looking for an expression for the .hgignore file, to ignore all files beneath a specified folder.
eg: I would like to ignore all files and folders beneath bin
Actually any advice on how the expressions are formed would be great
Alternately:
syntax: glob
bin/**
I did some experiments and I found that the regex syntax on Windows applies to the path starting with the current repository, with backslashes transformed to slashes.
So if your repository is in E:\Dev for example, hg status will apply the patterns against foo/bar/file1.c and such. Anchors apply to this path.
So:
Glob applies to path elements and is rooted to element parts
foo matches any folder (or file) named foo (not to "foobar" nor "barfoo")
*foo* matches any folder or file with "foo" in the name
foo/bar* matches all files in "foo" folder starting with "bar"
Regex is case sensitive, not anchored
Of course, backslash regex special characters like . (dot)
/ matches \ path separator on Windows. \ doesn't match this separator...
foo matches all files and folders with "foo" inside
foo/ matches only folders ending with "foo"
/foo/ matches the folder "foo" somewhere in the path
/foo/bar/ matches the folder "bar" in the folder "foo" somewhere in the path
^foo matches file or folder starting by foo at the root of the repository
foo$ matches file ending with foo
I hope this will help, I found the HGIGNORE(5) page a bit succinct.
Both of those will also filter out a directory called cabin, which might not be what you want. If you're filtering top-level, you can use:
^/bin/
For bin directories below your root, you can omit the ^. There is no need to specify syntax, regexp is the default.
syntax: glob
bin/**
This answer is shown above, however I'd also like to add that * and ** are handled differently. ** is recursive, * is not.
See Hg Patterns
Nevermind, I got it
syntax: regexp
bin\\*
expressions follow standard perl regular expression syntax.
to ignore .class files
syntax: regexp
?\.class