1

I have a grep command like below to search for all .xml files containing given string.

grep -rl 'product_list_toolbar_pager' --include='*.xml' --color=always

Now I am using this command on remote SSH terminal, where I am already inside the /home/user/public_html/ directory path, so from the result set of the above command, how can I trim the starting folders upto which I am already inside. Means if I run the above command inside /home/user then it should return result set containing paths starting from public_html/ but if I run the same from inside /home/user/public_html/ then it should return the paths starting from directory after public_html/.

Now about my second need, I want to filter the result set of the above command to only contain paths which have folder1/folder2 in their path heirarchy.

How can I acheive both these needs with minumum code as possible in SSH terminal ?

  • I'm not sure to understand your first query, do you want to include all the directory including public_html/ if the commande is ran in /home/user, or only the public_html/ directory? – Ikaros Nov 9 '16 at 12:57
  • As I mentioned in the question I need paths "starting from" the public_html/ if I am inside /home/user/ and I need paths starting after(containing all the rest of the subfolders along the found path) public_html/ if I am inside home/user/public_html/. – Vicky Dev Nov 9 '16 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.