What it is about:
I want to get a text-block containing the header and all occurrencies of strings appearing in this text-block.
Looking for some magic using sed
What i have so far is a code that prints every single occurrence with the corresponding header:
Code: Select all
# ls -AhlpR /mnt/sda3/x86_64/ | sed -ne '/^\//h;/.* \+.* \+.* \+.* \+.* \+.* \+.* \+.*spot/{x;s/^\//\n\//;p;x;p}'
/mnt/sda3/x86_64/:
-rw-r--r-- 1 root root 492K Jan 8 09:58 .ff_esr_64-spotprofile.tar.gz
/mnt/sda3/x86_64/brave-browser:
-rw-r--r-- 1 root root 26M Aug 25 2021 brave-spotprofile.tar.gz
/mnt/sda3/x86_64/brave-browser:
-rwxr-xr-x 1 root root 453 Jul 14 2021 save-spot
/mnt/sda3/x86_64/light:
-rw-r--r-- 1 root root 369K Sep 24 2021 light-spotprofile.tar.gz
/mnt/sda3/x86_64/light:
drwx------ 8 spot spot 4,0K Jan 14 16:35 spot/
/mnt/sda3/x86_64/min-browser:
-rw-r--r-- 1 root root 3,4M Nov 27 16:24 min-spotprofile-221127-180223.tar.gz
/mnt/sda3/x86_64/min-browser:
-rw-r--r-- 1 root root 3,3M Nov 27 18:02 min-spotprofile.tar.gz
/mnt/sda3/x86_64/min-browser:
-rwxr-xr-x 1 root root 416 Aug 26 2021 save-spot
/mnt/sda3/x86_64/palemoon:
-rw-r--r-- 1 root root 90K Aug 20 2022 pm64-spotprofile.tar.gz
/mnt/sda3/x86_64/seamonkey:
-rw-r--r-- 1 root root 4,9M Apr 6 2022 seamonkey-spotprofile.tar.gz
/mnt/sda3/x86_64/slimjet:
-rwxr-xr-x 1 root root 457 Aug 13 2021 save-spot
My desired output would look like:
Code: Select all
/mnt/sda3/x86_64/:
-rw-r--r-- 1 root root 492K Jan 8 09:58 .ff_esr_64-spotprofile.tar.gz
/mnt/sda3/x86_64/brave-browser:
-rw-r--r-- 1 root root 26M Aug 25 2021 brave-spotprofile.tar.gz
-rwxr-xr-x 1 root root 453 Jul 14 2021 save-spot
/mnt/sda3/x86_64/light:
-rw-r--r-- 1 root root 369K Sep 24 2021 light-spotprofile.tar.gz
drwx------ 8 spot spot 4,0K Jan 14 16:35 spot/
/mnt/sda3/x86_64/min-browser:
-rw-r--r-- 1 root root 3,4M Nov 27 16:24 min-spotprofile-221127-180223.tar.gz
-rw-r--r-- 1 root root 3,3M Nov 27 18:02 min-spotprofile.tar.gz
-rwxr-xr-x 1 root root 416 Aug 26 2021 save-spot
/mnt/sda3/x86_64/palemoon:
-rw-r--r-- 1 root root 90K Aug 20 2022 pm64-spotprofile.tar.gz
/mnt/sda3/x86_64/seamonkey:
-rw-r--r-- 1 root root 4,9M Apr 6 2022 seamonkey-spotprofile.tar.gz
/mnt/sda3/x86_64/slimjet:
-rwxr-xr-x 1 root root 457 Aug 13 2021 save-spot
I don't want to change formatting of ls
's output and i don't want to match a user or group in my pattern.
Any suggestions on this???