perforce filespec regex format - perforce

I am trying to restrict a user from being able to write to .c files in a depot location. I found 2 ways to achieve this. Add
=write growth * -//depot/new_team/....c
or
=write growth * -//depot/new_team/.../*.c
to protect table. Are both of these correct? Does one have preference over other?

They are very similar but not identical.
//depot/new_team/....c
This selects all files that end in .c anywhere under //depot/new_team/. For example, it matches //depot/new_team/foo.c as well as //depot/new_team/dir/foo.c.
//depot/new_team/.../*.c
This selects all files that end in .c in subdirectories of //depot/new_team/. It matches //depot/new_team/dir/foo.c but not //depot/new_team/foo.c. In the case of //depot/new_team/foo.c, it is not a match because your pattern asks for a slash between ... and *.c, but //depot/new_team/foo.c doesn't have one.

Related

Linux rename multiple files

I have some files named in a specifc pattern, for example, ab_2000_1.jpg. In this name 2000 is representing years and 1 representing month(1 means january). I have a 20 years of monthly files like this.
Now I want to rename every one of them into the following format ab_2000_1_12.jpg, ab_2000_2_12.jpg, etc
I know how to rename files using rename and sed command. But I want to know how can I loop this command for all files.
Any help is highly appreciated.
You can use a for loop to loop over all file names matching a pattern as for file in pattern; do some_commands; done.
You don't need sed to modify the file name in this case. A variable substitution like ${variable%pattern} will remove the shortest string matching pattern from the end of the variable value.
The following example code will remove .jpg from the end of the file name and append _12.jpg to the result.
for file in ab_*_*.jpg
do
mv "$file" "${file%.jpg}_12.jpg"
done

rename command for replacing text in filename from a certain point (character), but only up to, and maintaining the file extension

I've got a ton of files as follows
audiofile_drums_1-ktpcwybsh5c.wav
soundsample_drums_2-fghlkjy57sa.wav
noise_snippet_guitar_5-mxjtgqta3o1.wav
louder_flute_9-mdlsiqpfj6c.wav
I want to remove everything between and including the "-" and the .wav file extension, to be left with
audiofile_drums_1.wav
soundsample_drums_2.wav
noise_snippet_guitar_5.wav
louder_flute_9.wav
I've tried to do delete everything following and including the character "-" using
rename 's/-.*//' *
Which gives me
audiofile_drums_1
soundsample_drums_2
noise_snippet_guitar_5
louder_flute_9
And for lack of finding an easy way to rename all the files again, adding .wav the extension, I am hoping there is a slicker way to do this in one nifty command in one stage instead of 2.
Any suggestions?
Thanks
You can use rename 's/-[^\.]*\.wav$/\.wav/' *
The first part -[^\.]*\.wav$ searchs for a - followed by n chars that are not . followed by .wav and the end of filename. The end of filename and .wav is not strictly needed but it helps avoid renaming files you don't want to rename.
The /\.wav/ preserves the extension.
Please not that rename is not a standard utility, and is part of perl, so rename may not be available on every linux system.
This works in my specific case, but should work for any file extension.
rename -n 's/-.*(?=\.wav$)//' *
The command looks for all characters after and inclusive of the - symbol in the filename, then, using a positive lookahead** (?=\.wav$) to search for the characters (the file extension in this case) at the end of the filename (denoted by $, and replaces them with no characters (removing them).
** NOTE: A positive look ahead is a zero width assertion.
It will affect the match but it will not be included
in the replacement. (The '.wav' part will not be
erased)
In this example (?=\.wav$) is the positive lookahead. The dollar sign $, as in regex, denotes at the end of the line, so perfect for a file extension.

copy and append specific lines to a file with specific name format?

I am copying some specific lines from one file to another.
grep '^stringmatch' /path/sfile-*.cfg >> /path/nfile-*.cfg
Here what's happening: its creating a new file called nfile-*.cfg and copying those lines in that. The file names sfile- * and nfile- * are randomly generated and are generally followed by a number. Both sfile-* and nfile-* are existing files and there is only one such file in the same directory. Only the number that follows is randomly generated. The numbers following in sfile and nfile need not be same. The files are not created simultaneously but are generated when a specific command is given. But some lines from one file to the another file needs to be appended.
I'm guessing you actually want something like
for f in /path/sfile-*.cfg; do
grep '^stringmatch' "$f" >"/path/nfile-${f#/path/sfile-}"
done
This will loop over all sfile matches and create an nfile target file with the same number after the dash as the corresponding source sfile. (The parameter substitution ${variable#prefix} returns the value of variable with any leading match on the pattern prefix removed.)
If there is only one matching file, the loop will only run once. If there are no matches on the wildcard, the loop will still run once unless you enable nullglob, which changes the shell's globbing behavior so that wildcards with no matches expand into nothing, instead of to the wildcard expression itself. If you don't want to enable nullglob, a common workaround is to add this inside the loop, before the grep;
test -e "$f" || break
If you want the loop to only process the first match if there are several, add break on a line by itself before the done.
If I interpret your question correctly, you want to output to an existing nfile, which has a random number in it, but instead the shell is creating a file with an asterisk in it, so literally nfile-*.cfg.
This is happening because the nfile doesn't exist when you first run the command. If the file doesn't exist, bash will fail to expand nfile-*.cfg and will instead use the * as a literal character. This is correct behaviour in bash.
So, it looks like the problem is that the nfile doesn't exist when you start your grep. You'll need to create one.
I'll leave code to others, but I hope the explanation is useful.

Difference between * and ** in Vim file search patterns

I read Vim's help on file-searching where * and ** file searching operators are explained (both cited below). While I grasp that ** matches only directories (with limitation of 30 directories deep by default) and * matches everything (including /), I don't think I understand why there is a need for both of them and what are the use cases for each.
Also, how to match only the files in the listed directory? directory/* would match files in subdirectories (e.g. directory/subdirectory/) as well, right? Wouldn't they compliment each other better if * would match only files in the listed directory (without subdirectories)?
Vim documentation:
The usage of '*' is quite simple: It matches 0 or more characters. In a
search pattern this would be ".*". Note that the "." is not used for file
searching.
'**' is more sophisticated:
- It ONLY matches directories.
- It matches up to 30 directories deep by default, so you can use it to
search an entire directory tree
- The maximum number of levels matched can be given by appending a number
to '**'.
No, just like in wildcards, * does not match /.
In all of the (quite few) cases where these are used, vim is either only looking for files or only looking for directories, so there is no problem with directories matching where you want files.

Searching hundreds of org-mode files without loading them into Emacs?

I've compiled hundres of org-mode files in a specific directory.
Is there any way to search these files for specific keywords, or build agendas,
without loading them into Emacs, possibly using external search tools such as `ag'?
You can search them using Icicles. In Icicle minor mode, C-x C-f is bound to a multi-completion command that lets you match against the file name or the file content, or both. You can change the match patterns on the fly. Buffer *Completions* shows you the files that match.
And you can use progressive completion, combining any number of search patterns. Each pattern can itself be a regexp (or a substring), but it is a lot easier to combine several simple patterns than it is to come up with one complex pattern to DTRT. You can also negate patterns (obtain the complement of the match set).
You can visit any of the matching files that you like -- any number of them during the same command invocation. Or you can visit none of them if you like (C-g), and just use the command to locate those that match. You can use C-M-RET, C-M-down, etc. to get information about particular matching files (file type, permissions, size, last access time, creation time, etc.).
You can act on any number of them in some other way than visiting, using an alternate function that you specify: Just bind variable icicle-candidate-alt-action-fn to this function in a command you write that invokes icicle-find-file-of-content. Lots more features --- see Icicles - File-Name Input.

Resources