Jump to content


p4 grep - Without printing the line

p4 commands grep cmd

  • Please log in to reply
5 replies to this topic

#1 Elliott Lock

Elliott Lock

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 17 October 2017 - 08:08 AM

Hi,

I'm running the following command:

p4 grep -a -n -e "textToFind" "//streams/development/textFile.txt"

This outputs something similar to the following:

//streams/development/textFile.txt#405:14048:sometextMoreTexttextToFindsometextMoreTextsometextMoreTextsometextMoreText

The only information I really want to output is the file revision and the line number. So:
//streams/development/textFile.txt#405:14048

How would I modify my original command to do this?

Many Thanks

#2 P4Reg

P4Reg

    Advanced Member

  • Staff Moderators
  • 92 posts

Posted 17 October 2017 - 09:58 AM

You can use p4's -ztag and -F formatting option to filter just those fields:

p4 -ztag -F "%depotFile% %line%" grep -a -n -e "//streams/development/textFile.txt"


As well as the available variable names (those enclosed in %%, you can see a list using -ztag without the -F option), you can use free text so to replicate the output with the embedded "#" as well use:

p4 -ztag -F "%depotFile%#%line%" grep -a -n -e "//streams/development/textFile.txt"
  

You can read more about the -F option here in the following blog post https://www.perforce.../fun-formatting and in this Knowledge Base article Formatting p4 command output using the -F global option with examples

#3 Elliott Lock

Elliott Lock

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 17 October 2017 - 11:02 AM

Is it not possible to perform the grep command on lines with more than 4096 characters?

#4 Elliott Lock

Elliott Lock

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 17 October 2017 - 01:01 PM

I have this working for reporting the file and line number. But not the revision. I think I'm misunderstanding the formatting. How would you add the file revision between the two items?

#5 P4Reg

P4Reg

    Advanced Member

  • Staff Moderators
  • 92 posts

Posted 17 October 2017 - 01:56 PM

View PostElliott Lock, on 17 October 2017 - 11:02 AM, said:

Is it not possible to perform the grep command on lines with more than 4096 characters?

4096 is the default maximum line length for grep. You can increase the settings for these 2 server configurables that relate to grep:

From p4 help undoc:

        dm.grep.maxlinelength 4096 Maximum line length that can be searched
        dm.grep.maxcontext      1K Maximum size of context allowed for grep

View PostElliott Lock, on 17 October 2017 - 01:01 PM, said:

I have this working for reporting the file and line number. But not the revision. I think I'm misunderstanding the formatting. How would you add the file revision between the two items?

You can use %rev%:


p4 -ztag -F "%depotFile% %rev% %line%" grep -a -n -e "//streams/development/textFile.txt"

#6 Elliott Lock

Elliott Lock

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 21 October 2017 - 10:59 PM

Thanks very much for this





Also tagged with one or more of these keywords: p4 commands, grep, cmd

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users