I was wondering if there is a keyword in P4 that expands to just YYYY, I'd like to automatically ensure that the copyright year is uptodate when a file is changed.
The $DATE keyword expands to more than just the year, so that doesn't quite work.
Thanks
Related
I am taking an assessment and stumbled across the following sample question, but when I run the line it's none of the options? Which is the correct answer?
That code looks more like PHP. . is the concatenation operator, and it can be used with both strings and numbers (it will convert the number to a string). The output will be
Tomorrow will be January 3rd
In bash, . has no special meaning, so it will be echoed literally. The echo command puts a space between each argument, so the output will be
Tomorrow . will be January . 3 . rd
. is the string concatenation operator for PHP. In bash, you could just do echo Tomorrow will be January ${num}rd.
Both versions of the code output Tomorrow will be January 3rd.
I would like to rename many files in this format
abc.123.fits
abcd.1234.fits
efg.12.fits
to this format
abc.fits
abcd.fits
efg.fits
I tried the rename function, but since the part I'm trying to replace is not the same in all files, it did not work. I am using Linux.
for f in *; do mv "$f" "${f%%.*}.${f##*.}"; done`
${f%%.*} removes everything after the first period, including the period. ${f##*.} removes everything before the last period, including the period (i.e. it gets the file extension). Concatenating these two, with a period between them, gives you the desired result.
You can change the * to a more restrictive pattern such as *.fits if you don't want to rename all files in the current directory. The quotes around the parameters to mv are necessary if any filenames contain whitespace.
Many other variable substitution expressions are available in bash; see a reference such as TLDP's Bash Parameter Substitution for more information.
I am trying to do a code walk through a badly written bash script.
I have come across this statement:
FOOBAR_NAME=`date +WeekNo.%W`
There are no prior declarations of any of the RHS variables in the script, lines preceding this statement.
So my question is:
What does FOOBAR_NAME resolve to, when it is used a few lines down in the script as $FOOBAR_NAME ?
Try it!
$date +WeekNo.%W
WeekNo.30
There are no variables being referenced in the RHS.
The backtick operator (`` ) evaluates its contents and returns the output, similar (identical?) to$(). It's a quick way to write aneval` (in other languages).
Type date +WeekNo.%W in a shell. What is printed (in stdout, with newlines collapsed) is what will be stored in FOOBAR_NAME.
Note that the evaluation occurs only once, which is during the assignment. date isn't executed each time you reference FOOBAR_NAME.
See man date for a description of the date command and it's formatting options. %W is week number.
This is using a format string to the date command to create the a string that contains the week number.
The backticks execute the command between them; and the line assigns the result to the shell variable FOOBAR_NAME.
So if you really want to know what it does, just cut and paste the text between the `` into a shell and execute it.
You can find the answer in man date: If you specify an argument starting with +, then the rest of that argument is taken as a format string. The Weekno. part is taken literally, the %W does:
%W week number of year, with Monday as first day of week (00..53)
The assignment operator ("=") assigns the value on its right part to a variable on the left part. Here the variable is FOOBAR_NAME.
The right part is a subshell. The backticks ("`` `") create a subshell. The output of that subshell will go to the variable.
The subshell rurns the Unix date command. The manual page for all Unix commands is on the Internet. There a Unix man page for date. Here, %W will be replaced by the number of the week.
So the variable gets the value "WeekNo" plus the number of the week.
Does anyone know if there's a way to format the date generated by strftime in Vim (under MS Windows) such that Month, Day, and Hour are not padded to two digits with a leading zero?
For example, the following commands in vimrc:
nmap <F3> a<C-R>=strftime("%I:%M %p %m/%d/%Y ")<CR><Esc>
imap <F3> <C-R>=strftime("%I:%M %p %m/%d/%Y ")<CR>
will print
03:32 AM 07/09/2010
into the file, if it was actually July 9th.
I'd like to know if there's a format string that will print
3:32 AM 7/9/2010
for vim instead. I know strftime is platform-specific, so I'm looking for a Windows-specific solution, without the use of external tools. I'd also appreciate comments to the effect that this is impossible with those constraints.
Thanks.
Some operating systems support %k and %e for the single-digit hour and day, respectively. Neither of these seem to be supported on Windows (or not on Windows XP, at least, which is all I've got nearby to try it on).
But all is not lost. Windows does support %x, which gives the date in the 7/9/2010 format you want, and we can get rid of any leading zero with a call to substitute():
echo substitute(strftime("%I:%M %p %x"), "^0", "", "")
This prints
3:50 AM 7/19/2010
Keep in mind that all of this is specific not only to the OS, but also to the current locale. This really isn't portable at all.
I don't know if there are any ways to tell strftime() how to generate what you are looking for. However, you can still apply a substitute(strftime(...), '\<0\+\ze\d', '', 'g').
On occasion, I find myself wanting to search the text of changelist descriptions in Perforce. There doesn't appear to be a way to do this in P4V. I can do it by redirecting the output of the changes command to a file...
p4 changes -l > p4changes.txt
...(the -l switch tells it to dump the full text of the changelist descriptions) and then searching the file, but this is rather cumbersome. Has anyone found a better way?
When the submitted changelist pane has focus, a CTRL+F lets you do an arbitrary text search, which includes changelist descriptions.
The only limitation is that it searches just those changelists that have been fetched from the server, so you may need to up the number retrieved. This is done via the "Number of changelists, jobs, branch mappings or labels to fetch at a time" setting which can be found by navigating to Edit->Preferences->Server Data.
p4 changes -L | grep -B 3 searchstring
-B 3 means show 3 lines before the matched string, should be enough to show the change id with 2 line comments but you can change it as necessary.
I use p4sql and run a query on the "changes" database. Here's the perforce database schema
The query looks something like this (untested)
select change from changes where description like '%text%' and p4options = 'longdesc'
edit: added the p4options to return more than 31 characters in the description.
Here is a Powershell version of Paul's "grep" answer. Again, it searches for the specified string within the change description and returns the 3 lines before it, to include the change id:
p4 changes -L | select-string "search string" -Context (3,0)
Why redirect to a file when you can pipe the output through less and use less's search?
p4 changes -l | less
And then press / to prompt for a search string. Afterward, n will jump to the next match, and Shift+n will jump to the previous one.
An implementation of less for Windows is available as part of UnxUtils.
Using p4sql is really the only way to effectively do what you want. I am not aware of any other way. The benefit of course is that you can use the select statements to limit the range of changelist values (via date, user, etc). Your method will work but will get cumbersome very quickly as you generate more changelists. You can limit the scope of the changes command, but you won't get the flexibility of p4sql.
Eddie on Games posted his Perforce Changelist Search 0.1 at http://www.eddiescholtz.com/blog/archives/130
But, I do like using my favorite text editor with the simple:
p4 changes -s submitted //prog/stuff/main/... >temp.txt
If you still love your command line, you can write a small perl script that:
changes the record separator $/ to
double newline "\n\n" so it filters
the input into full records of the
ztagged p4 output.
scans
the '/^... desc/..//' part with
regular expressions from the args.
usage would be something like 'p4 -ztag changes -l | yourperlfilter.pl searchterm1 searchterm2'
if that worked ok, you could integrate it into the p4win tools menu.