Tag Info

Hot answers tagged

6

Just make use of FILENAME built-in variable: awk -F, '$32 > 3000{print FILENAME; nextfile}' *


6

Using prefixes or suffixes is common, because it's easily filtered. It's usually ~ for backup. Most text editors use this, and it is possible to explicitly tell ls to not list them by default. This is similar to using a period at the beginning to make the file somewhat hidden (this is also respected by ls and by shell globbing). Other examples are ...


2

If you want to use shell parameter expansion then run some shell with exec: find . -type f -exec sh -c 'echo "${0##*.}"' {} \;


2

export clv="/third/party/city of las vegas" Is the same as export clv=/third/party/city\ of\ las\ vegas Either way, you still need to quote the variable. cd "$clv" The shell will break unquoted expansions on whitespace by default. Remembering to quote variables in contexts like this is a more conventional and probably safer practice. Note that "one\ ...


2

With zsh: diff -u <(cd dir1 && printf '%s\n' **/*(D:r)) \ <(cd dir2 && printf '%s\n' **/*(D:r)) (D) to include dot-files (hidden files), :r to get the rest (remove extension). Using globbing guarantees a consistent sort order. (that assumes file names don't have newline characters).


2

You could use this command: comm -12 <(find dir1 -type f -exec bash -c 'basename "${0%.*}"' {} \; | sort) <(find dir2 -type f -exec bash -c 'basename "${0%.*}"' {} \; | sort) This uses find to list all the files in each directory, then basename and parameter substitution to strip off the directory names and file extensions. comm compares the two ...


2

That's typically where you'd use the hold space: ls | sed ' /\.png$/!d; # discard everything but lines ending in .png s///; # remove that .png h; # store on the hold space s/_//g; # remove underscores H; # append (with a newline) to the hold space g; # retrieve that hold space s|\n|/|; # substitute the ...


1

find . -type f | while read file; do echo "${file##*.}"; done Has the advantage of bypassing all that tricky exec syntax that no one can ever remember. Also has the advantage of only creating one child process, instead of creating and destroying one for every found file. This is considerably faster than jimmij's version using exec # Preparation - 1000 ...


1

You can install the Perl script rename. Then try doing this : $ rename -n 's/[A-Z]/lc($&)/ge; s/\s/_/g' files* (remove the -n switch when your tests are OK) There are two utilities called rename. The one in Fedora can't do this. Some other distributions come with the Perl one by default. If you run the following command (GNU) $ file ...


1

Before answering your answer, I highly recommend you reading two question: Why does my shell script choke on whitespace or other special characters? Security implications of forgetting to quote a variable in bash/POSIX shells For your question, you don't need a for loop, just find itself: find -type d If you want to do more things, just use -exec ...


1

If you're really just looking to echo the results of find, you can use the parameter -print (or just no additional parameter at all) to have find print a list of its results. If you want to delete the results, there's -delete (which can be combined with -print to get a list of the deleted files). If you want to do something else with/to the results, you ...


1

Something like the following works ... find . -type d | while read dir; do echo $dir; done . ./my dir Depending on what you're doing, you might be better using find's -print0 option and xargs -0. The code you've got takes the unquoted output from find and uses it as a list of words (split on whitespace) for for to iterate over.


1

Do not use for loop, use while instead: find . -type d -print0 | while read -d '' -r dir; do echo "$dir"; done Option print0 prints NULL character at the end of file/directory name (instead of newline) and read -d '' interprets it properly.



Only top voted, non community-wiki answers of a minimum length are eligible