I use the following command in Git Bash to search for Java classes using non ASCII characters:
find */src/*/java -name "*.java" -print0 | xargs -0 ggrep -lP "[\x80-\xFF]"
I get the error:
xargs: ggrep: no such file or directory
Any other way to run this command in Windows 7?
Related
I'm building a website that uses the Angular Material design package. Recently after an update, the package changed the names of many CSS styling classes, thus breaking old code. The package provided a command that can be run to replace all instances of the old name in .css and .scss files with the new name (source):
find . -type f -name "*.scss" -o -name "*.css"| xargs sed -i 's/\.md-/\.mat-/g'
I think this is meant to replace all .md- with .mat- in the styling files found in the project directory and sub-directories. After making sure that I can run both find and xargs on my Windows machine, I tried to run the command. Here is what I get:
C:\project>find . -type f -name "*.scss" -o -name "*.css"| xargs sed -i 's/\.md-/\.mat-/g'
File not found - "*.css"
sed: no input files
C:\project>find . -type f -name "*.scss"| xargs sed -i 's/\.md-/\.mat-/g'
Access denied - .
File not found - -TYPE
File not found - F
File not found - -NAME
sed: no input files
IRunning as Aministrator makes no difference. I have no idea where to go from here. What's the matter? Is there a different way to do this on Windows 7?
Provided that you have a proper xargs and sed on your Windows system, you can try using dir instead of find, something like:
dir /b /s *.*css | xargs sed -i 's/\.md-/\.mat-/g'
I'm trying to script changing files that do not have DOS line endings to change them to have DOS line endings, but I'm hungup on how to locate the files that don't contain DOS line endings.
I have the following command that works on linux
$ find -type f -exec file {} \; | grep -v CRLF
it works and returns
./test/test.bat: ASCII text
However, on OSX I get
$ find -type f -exec file {} \; | grep -v CRLF
find: illegal option -- t
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
I've also tried
$ find . -type f -exec file {} \; | grep -v CRLF
cannot open `' (No such file or directory)
cannot open `' (No such file or directory)
cannot open `' (No such file or directory)
cannot open `' (No such file or directory)
... etc
Is there different syntax that should be used with find on OSX to accomplish this?
The BSD find used on MacOS X requires a path to be provided before the expression (your -type f being part of that expression); hence its usage message putting path outside of [brackets], which indicate that something is optional.
Use -- to prevent filenames from being treated as options, and explicitly pass . as the location to search.
find . -type f -exec file -- '{}' + | grep -v CRLF
...has been explicitly tested on MacOS 10.11.6.
To better track down the error, consider the following:
find . -type f -exec bash -c '
for result; do
file "$result" 2>/dev/null || {
printf "Unable to run file against %q\n" "$result"
}
done
' _ {} +
I'm trying to get rid off all my Dropbox files including "File foo in conflict with copy from ..." I tried several lines of code but non of them worked so far :(
find | grep conflict | xargs -0 rm ""
Error: filename too long for rm because there is no file/line separator
When i use the following:
find | grep conflict | head -1 | xargs rm ""
I get errors because the filename contains spaces. What line of code should I choose to get rid of this problem?
You don't need xargs, you can do it directly with find:
find . -name '*conflict*' -delete
Alternatively, you could execute rm:
find . -name '*conflict*' -exec rm -- {} \+
-- prevents problems with file names that start with a dash. (Hat tip: mklement0)
find . -name '*conflict*' -print0 | xargs -0 rm
Here is my .bowerrc:
{
"directory": "vendor/assets/bower",
"scripts": {
"postinstall": "find ./vendor/assets/bower -name '*.html' -print0 | xargs -0 sed -i '' -E -e 's/href=\"https?:\\/\\//href=\"\\/\\//g'"
}
}
This is suppose to replace all instances of href="https:// with href="//. I did this to fix a bug with my build system.
I'm getting this error:
bower postinstall find ./vendor/assets/bower -name '*.html' -print0 | xargs -0 sed -i '' -E -e 's/href="https?:\/\//href="\/\//g'
bower postinstall find: [object Object]: unknown primary or operator
bower ECMDERR Failed to execute "find ./vendor/assets/bower -name *.html -print0 [object Object] xargs -0 sed -i -E -e s/href="https?:\/\//href="\/\//g", exit code of #1 find: [object Object]: unknown primary or operator
Additional error details:
find: [object Object]: unknown primary or operator
Why is the pipe character converted to [object Object]? How do I make the command run?
I tried adding an escaped slash in front of the |:
"postinstall": "find ./vendor/assets/bower -name '*.html' -print0 \\| xargs -0 sed -i '' -E -e 's/href=\"https?:\\/\\//href=\"\\/\\//g'"
Now I'm getting:
bower ECMDERR Failed to execute "find ./vendor/assets/bower -name *.html -print0 | xargs -0 sed -i -E -e s/href="https?:\/\//href="\/\//g", exit code of #1 find: |: unknown primary or operator
I'm on OSX 10.10.5
I'm pretty sure Bower won't support this command. Have a look at this issue. It seems to work only on smallish commands like gulp postInstall for example. The reason being seems to make some assumptions about the command.
I think a fix would be to write this into a bash script, and run this bash script instead. So save this as 'postInstall.sh' with executable perms, and then change .bowerrc to have in the postInstall 'postInstall: ./postInstall.sh'
I'm trying to set up a simple bash alias that will open a solution file in the current directory via cygstart
I'm unsuccessfully trying something like
ls | grep '.sln' | cygstart $0
I'm no expert in bash commands and was wondering what the correct command is?
You want to try:
ls *.sln | xargs cygstart
or better:
find . -iname "*.sln" -print | xargs cygstart