Linux Lite Forums
grep - search for an "option" - text itself is a valid command parameter [solved - Printable Version

+- Linux Lite Forums (https://www.freecinema2022.gq/forums)
+-- Forum: General (https://www.freecinema2022.gq/forums/forumdisplay.php?fid=4)
+--- Forum: Off Topic (https://www.freecinema2022.gq/forums/forumdisplay.php?fid=15)
+--- Thread: grep - search for an "option" - text itself is a valid command parameter [solved (/showthread.php?tid=5517)



grep - search for an "option" - text itself is a valid command parameter [solved - Sprintrdriver - 08-09-2018

Hi folks. Have som beginner-issues using grep here.
I'm up to search for the term "--prune-empty-dirs" in the man page of rsync. So I tried to ran this command:
Code:
man rsync | grep '--prune' -A1 -B4'
Problem is I get error grep: unrecognized option '--prune'.[size=1em]How can I make grep to recognise the text pattern "--prune" as the pattern to search for?[/size][size=1em]I can remove the two dashes, but that is not what I want to do.[/size][size=1.45em][edit while write post][/size]Ok, I found the solution after I remembered to search the web for "grep escape character" (that is probably what I should had ask for) - so I got it to work with the same command, but backslashes in front of all dashes:
Code:
man rsync | grep '\-\-prune' -A1 -B4



Re: grep - search for an "option" - text itself is a valid command parameter [solved - kpanic - 08-29-2018

Use double quotes: man rsync | grep "\-\-prune" -A1 -B4

Please set the topic as solved even if you found the solution yourself. It saves time from the rest of us.
Thanks!