lsxzmgrep

Here is a place for your projects which are not officially supported by the Porteus Team. For example: your own kernel patched with extra features; desktops not included in the standard ISO like Gnome; base modules that are different than the standard ISO, etc...
Post Reply
User avatar
Ed_P
Contributor
Contributor
Posts: 5947
Joined: 06 Feb 2013, 22:12
Distribution: 4.0 & 5.0rc2 Cinnamon 64 ISOs
Location: Western NY, USA

lsxzmgrep

Post#1 by Ed_P » 17 Dec 2020, 04:48

Rava wrote:
15 Dec 2020, 20:06
too busy for having time to properly make lsxzmgrep more informative - without adding any bugs - but anyone if free to enhance it. :) *nudge* *nudge*
The best I could do.

Code: Select all

#!/bin/bash
# https://forum.porteus.org/viewtopic.php?p=80384#p80384 Rava
# https://forum.porteus.org/viewtopic.php?p=67979#p67979 brokenman
# https://forum.porteus.org/viewtopic.php?p=3522#p3522   82issa

if [ -z $1 ]; then
   echo No xzm name and grep search pattern specified. && read
   exit
fi 

echo -en "\033]0;lsxzmgrep.sh\a";

if [ `whoami` != "root" ]; then
  echo "Enter root's password" $(tput bold) $(tput setaf 1)
  su -c "sh $0 $1 $2"
  exit
fi
echo $(tput sgr0)

for module in $(find $1 -type f -name "*.xzm"); do
    lsxzm ${module} | grep "$2" | sed -r "s#.+#>${module}\n&#"
done
Added in 6 minutes 13 seconds:
Rava wrote:
16 Dec 2020, 17:38
when I am awake I also love taking moonlight strolls.
I love the sounds of that.
Last edited by Rava on 19 Dec 2020, 01:17, edited 1 time in total.
Reason: adjusted subject
Ed

User avatar
Rava
Contributor
Contributor
Posts: 2934
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc2 + 4.0 i586 XFCe
Location: Forests of Germany

Porteus 5.0 RC2 DE bug reports

Post#2 by Rava » 17 Dec 2020, 05:46

Thanks for the good work. Here my version with some minor changes.
file is meant to be /usr/local/bin/lsxzmgrep

Code: Select all

root@porteus:~# md5sum /usr/local/bin/lsxzmgrep
0a88e959966b3dbb6f8dc2b91534733c  /usr/local/bin/lsxzmgrep
Dr. Copy & Mr. Paste here:

Code: Select all

#!/bin/bash
# https://forum.porteus.org/viewtopic.php?p=67979#p67979 brokenman
# https://forum.porteus.org/viewtopic.php?p=3522#p3522   82issa
# https://forum.porteus.org/viewtopic.php?p=80427#p80427 Ed_P
# https://forum.porteus.org/viewtopic.php?p=80384#p80384 &
#  https://forum.porteus.org/viewtopic.php?p=80428#p80428 Rava
VERSION=2020-12-17
echo -n $(tput sgr0)

echo $(tput bold)$(tput setaf 3)lsxzmgrep$(tput sgr0) V$(tput setaf 3)${VERSION}$(tput sgr0)

if [ $# -ne 2 ]; then
   echo $(tput bold)$(tput setaf 1)No xzm name and grep search pattern specified.$(tput sgr0)
   exit 1
fi

if [ `whoami` != "root" ]; then
  echo "Enter root's password" $(tput bold) $(tput setaf 1)
  su -c "/bin/bash $0 $1 $2"
  echo -n $(tput sgr0)
  exit 0
fi

for module in $(find $1 -type f -name "*.xzm"); do
    lsxzm ${module} | grep "$2" | sed -r "s#.+#>${module}\n&#"
done
When run as guest and using | e.g. for |tail the bold red of Password: is not displayed.
Without any | all looks normal:
guest@porteus:/mnt/sda4/TEST$ lsxzmgrep . /usr/
lsxzmgrep V2020-12-17
Enter root's password
Password:
lsxzmgrep V2020-12-17
>./032-webp-pixbuf-loader-20191003.fb04954-x86_64-1_slonly.xzm
/usr/doc
>./032-webp-pixbuf-loader-20191003.fb04954-x86_64-1_slonly.xzm
/usr/doc/webp-pixbuf-loader-20191003.fb04954
[…]
, but with |tail
guest@porteus:/mnt/sda4/TEST$ lsxzmgrep . /usr/|tail
Password:
/usr/share/locale/ru
>./florence-0.6.3-x86_64-1_slonly.xzm
/usr/share/locale/ru/LC_MESSAGES
>./florence-0.6.3-x86_64-1_slonly.xzm
/usr/share/locale/ru/LC_MESSAGES/florence.mo
>./florence-0.6.3-x86_64-1_slonly.xzm
/usr/share/pixmaps
>./florence-0.6.3-x86_64-1_slonly.xzm
/usr/share/pixmaps/florence.svg
Password: is printed plain. Also observe that the info output of

Code: Select all

echo $(tput bold)$(tput setaf 3)lsxzmgrep$(tput sgr0) V$(tput setaf 3)${VERSION}$(tput sgr0)
is omitted.

Also: known bugs:
you can specify a single module via

Code: Select all

lsxzmgrep module.xzm pattern
or via

Code: Select all

lsxzmgrep /path/to/module.xzm pattern
or all modules in a folder via

Code: Select all

lsxzmgrep . pattern
when you are in said folder or via

Code: Select all

lsxzmgrep /path/to/modules/folder/ pattern
when you are not.

But for now you cannot specify specific modules:

Code: Select all

lsxzmgrep /path/to/module1.xzm /anotherpath/to/module2.xzm pattern
will fail.

And finally, if you do not want any non-root user able to execute lsxzmgrep you do not have to change the code.
Just do the following as root:

Code: Select all

root@porteus:/usr/local/bin# chown root.root lsxzmgrep
root@porteus:/usr/local/bin# chmod 0744 lsxzmgrep
Check as root:

Code: Select all

root@porteus:/usr/local/bin# ls -l  lsxzmgrep
-rwxr--r-- 1 root root 807 Dec 17 06:43 lsxzmgrep
root@porteus:/usr/local/bin# lsxzmgrep
lsxzmgrep V2020-12-17
No xzm name and grep search pattern specified.
Check as guest:

Code: Select all

guest@porteus:/mnt/sda4/TEST$ lsxzmgrep . /usr/
bash: /usr/local/bin/lsxzmgrep: Permission denied
When you want guest or any other non-root user able to execute lsxzmgrep I recommend this:

Code: Select all

root@porteus:/usr/local/bin# chown root.root lsxzmgrep
root@porteus:/usr/local/bin# chmod 0755 lsxzmgrep
root@porteus:/usr/local/bin# ls -l  lsxzmgrep
-rwxr-xr-x 1 root root 807 Dec 17 06:43 lsxzmgrep
I could even upload both versions as modules, one with lsxzmgrep set with chmod 0744 and one set with chmod 0755. But in my book that would be overkill.
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 5947
Joined: 06 Feb 2013, 22:12
Distribution: 4.0 & 5.0rc2 Cinnamon 64 ISOs
Location: Western NY, USA

Porteus 5.0 RC2 DE bug reports

Post#3 by Ed_P » 17 Dec 2020, 21:09

I like mine better. :P
Image
Ed

User avatar
Rava
Contributor
Contributor
Posts: 2934
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc2 + 4.0 i586 XFCe
Location: Forests of Germany

Porteus 5.0 RC2 DE bug reports

Post#4 by Rava » 18 Dec 2020, 05:13

Cave! I updated both versions!
Replaced

Code: Select all

for module in $(find $1 -type f,l -name "*.xzm"); do
with

Code: Select all

for module in $(find "$1" -type f,l -name "*.xzm"); do
Ed_P wrote:
17 Dec 2020, 21:09
I like mine better. :P
https://i.postimg.cc/1nkDdTn1/Screensho ... -35-02.png
I just realized, all our lsxzmgrep versions so far have the same fatal flaw.

To check it out do the following:
go to a folder either on a Linux partition or a NTFS partition created by SM-Witless7 or higher or created by mkntfs - any partition able to handle symbolic links will do.
Create a symlink to the module you want to search.
Call any lsxzmgrep version trying searching like above for "desktop" using the symlink name to reference the module.

See all lsxzmgrep version fail?

Why does it fail?
Also, lsxzmgrep uses lsxzm and lsxzm does not need root privilege, silly me forgot about that.

Ed_P's version should be shortened to

Code: Select all

#!/bin/bash
# https://forum.porteus.org/viewtopic.php?p=80384#p80384 Rava
# https://forum.porteus.org/viewtopic.php?p=67979#p67979 brokenman
# https://forum.porteus.org/viewtopic.php?p=3522#p3522   82issa

if [ -z $1 ]; then
   echo No xzm name and grep search pattern specified. && read
   exit
fi 

echo -en "\033]0;lsxzmgrep.sh\a";

echo $(tput sgr0)

for module in $(find "$1" -type f,l -name "*.xzm"); do
    lsxzm ${module} | grep "$2" | sed -r "s#.+#>${module}\n&#"
done
and mine to

Code: Select all

#!/bin/bash
# https://forum.porteus.org/viewtopic.php?p=67979#p67979 brokenman
# https://forum.porteus.org/viewtopic.php?p=3522#p3522   82issa
# https://forum.porteus.org/viewtopic.php?p=80427#p80427 Ed_P
# https://forum.porteus.org/viewtopic.php?p=80384#p80384 &
#  https://forum.porteus.org/viewtopic.php?p=80432#p80432 Rava
VERSION=2020-12-19
echo -n $(tput sgr0)

echo $(tput bold)$(tput setaf 3)lsxzmgrep$(tput sgr0) V$(tput setaf 3)${VERSION}$(tput sgr0)

if [ $# -ne 2 ]; then
   echo $(tput bold)$(tput setaf 1)No xzm name and grep search pattern specified.$(tput sgr0)
   exit 1
fi

for module in $(find "$1" -type f,l -name "*.xzm"); do
    lsxzm ${module} | grep "$2" | sed -r "s#.+#>${module}\n&#"
done
One issue with using

Code: Select all

-type f,l 
instead of

Code: Select all

-type f
is that if the symlink one uses when executing lsxzmgrep as $1 is a reference to a folder ending with .xzm lsxzm would fail.
But why would someone name a folder

Code: Select all

program-version-arch.xzm
instead of

Code: Select all

program-version-arch
and even create a symlink to the folder program-version-arch.xzm and then running lsxzmgrep, knowing $1 should reference a path to modules to search or one module - but not one folder that is not a module but still ends in .xzm

find might be able to exclude folders but I have to delve even deeper into find syntax to get a solution supporting

Code: Select all

-type f,l
while excluding folders referenced to by a symlink - when that symlink name to the folder ends in .xzm .

User avatar
Ed_P
Contributor
Contributor
Posts: 5947
Joined: 06 Feb 2013, 22:12
Distribution: 4.0 & 5.0rc2 Cinnamon 64 ISOs
Location: Western NY, USA

Porteus 5.0 RC2 DE bug reports

Post#5 by Ed_P » 18 Dec 2020, 14:10

Does your version support:

lsxzmgrep.sh *Ed_P*.xzm Rava

:hmmm:
Ed

User avatar
Rava
Contributor
Contributor
Posts: 2934
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc2 + 4.0 i586 XFCe
Location: Forests of Germany

lsxzmgrep

Post#6 by Rava » 19 Dec 2020, 00:53

Ed_P wrote:
18 Dec 2020, 14:10
Does your version support:

lsxzmgrep.sh *Ed_P*.xzm Rava

:hmmm:
Considering

Code: Select all

*Ed_P*.xzm
refers to one module only, it sure does.

When it refers to more than one module, it would mean $1 is e.g. whatever_Ed_P-1.xzm, $2 is whatevs-Ed_P-2.xzm and $3 is whatevs-Ed_P-3.xzm

Meaning it would examine whatever_Ed_P-1.xzm and looking for whatevs-Ed_P-2.xzm. I presume that is not what you want, but that is true for your version as well due to the

Code: Select all

for module in $(find $1 -type f -name "*.xzm"); do
    lsxzm ${module} | grep "$2" | sed -r "s#.+#>${module}\n&#"
done
part in your script.

Here is the proof, lsxzmgrep and lsxzmgrep.sh are both the versions from the post above yours. ( aka lsxzmgrep (Post by Rava #80428) ) Be aware that I updated both. (My update concerns only handling of a module as parameter $1 with a whitespace in its name)
guest@porteus:/mnt/sda1/Porteus_5.0rc2/porteus/base$ l *RedshiftGUI*xzm
lrwxrwxrwx 1 root 172 2020-11-01 02:23 023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm -> /mnt/sda1/Porteus_5.0rc1/porteus/base/023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm
guest@porteus:/mnt/sda1/Porteus_5.0rc2/porteus/base$ file *RedshiftGUI*xzm
023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm: symbolic link to /mnt/sda1/Porteus_5.0rc1/porteus/base/023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm
guest@porteus:/mnt/sda1/Porteus_5.0rc2/porteus/base$ lsxzmgrep *RedshiftGUI*xzm desktop
lsxzmgrep V2020-12-19
>023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm
/usr/share/applications/redshiftgui.desktop
guest@porteus:/mnt/sda1/Porteus_5.0rc2/porteus/base$ lsxzmgrep.sh *RedshiftGUI*xzm desktop

>023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm
/usr/share/applications/redshiftgui.desktop
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 5947
Joined: 06 Feb 2013, 22:12
Distribution: 4.0 & 5.0rc2 Cinnamon 64 ISOs
Location: Western NY, USA

lsxzmgrep

Post#7 by Ed_P » 21 Dec 2020, 15:13

Rava wrote:
17 Dec 2020, 05:46
all modules in a folder via

Code: Select all

lsxzmgrep . pattern
If this works it would seem to indicate that
Ed_P wrote:
18 Dec 2020, 14:10
lsxzmgrep.sh *Ed_P*.xzm Rava
should work also. Unfortunately it doesn't. :(
Ed

User avatar
Rava
Contributor
Contributor
Posts: 2934
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc2 + 4.0 i586 XFCe
Location: Forests of Germany

lsxzmgrep

Post#8 by Rava » 21 Dec 2020, 15:39

^
Firstly, which version of lsxzmgrep.sh are you referring to?
Your original version from lsxzmgrep (Post by Ed_P #80427) or my altered one from Porteus 5.0 RC2 DE bug reports (Post by Rava #80432) ?

lsxzmgrep.sh *Ed_P*.xzm desktop from my versions of post #p80432 works in both lsxzmgrep and lsxzmgrep.sh variants - when "*Ed_P*.xzm" is referring to only one module.

Lookie here:

Code: Select all

guest@porteus:/tmp$ mkdir lsxzmgreptest
guest@porteus:/tmp$ cp $PORTDIR/base/023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm lsxzmgreptest
guest@porteus:/tmp$ cd lsxzmgreptest
guest@porteus:/tmp/lsxzmgreptest$ l
total 420
drwxr-xr-x  2 guest     60 2020-12-21 16:20 .
drwxrwxrwt 20 root    1260 2020-12-21 16:19 ..
-rwxrwxrwx  1 guest 430080 2019-01-26 17:06 023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm
guest@porteus:/tmp/lsxzmgreptest$ ln -s 023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm  Ed_P-test-module.xzm
guest@porteus:/tmp/lsxzmgreptest$ l
total 420
drwxr-xr-x  2 guest     80 2020-12-21 16:20 .
drwxrwxrwt 20 root    1260 2020-12-21 16:19 ..
-rwxrwxrwx  1 guest 430080 2019-01-26 17:06 023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm
lrwxrwxrwx  1 guest     44 2020-12-21 16:20 Ed_P-test-module.xzm -> 023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm
guest@porteus:/tmp/lsxzmgreptest$ lsxzmgrep *Ed_P*.xzm desktop
lsxzmgrep V2020-12-19
>Ed_P-test-module.xzm
/usr/share/applications/redshiftgui.desktop
guest@porteus:/tmp/lsxzmgreptest$ lsxzmgrep.sh *Ed_P*.xzm desktop

>Ed_P-test-module.xzm
/usr/share/applications/redshiftgui.desktop
Remember my alias if you want the exact same results than above:

Code: Select all

guest@porteus:/tmp/lsxzmgreptest$ type l
l is aliased to `/bin/ls -oa --color=auto --time-style=long-iso'
Remember²:
If *Ed_P*.xzm refers to more than one module the scripts will fail:

Code: Select all

guest@porteus:/tmp/lsxzmgreptest$ ln -s 023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm 2ndEd_P-test-module.xzm
guest@porteus:/tmp/lsxzmgreptest$ l
total 420
drwxr-xr-x  2 guest    100 2020-12-21 16:28 .
drwxrwxrwt 20 root    1260 2020-12-21 16:19 ..
-rwxrwxrwx  1 guest 430080 2019-01-26 17:06 023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm
lrwxrwxrwx  1 guest     44 2020-12-21 16:28 2ndEd_P-test-module.xzm -> 023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm
lrwxrwxrwx  1 guest     44 2020-12-21 16:20 Ed_P-test-module.xzm -> 023-RedshiftGUI-0.2.4-Linux-x86_64-Fixed.xzm
guest@porteus:/tmp/lsxzmgreptest$ lsxzmgrep *Ed_P*.xzm desktop
lsxzmgrep V2020-12-19
No xzm name and grep search pattern specified.
guest@porteus:/tmp/lsxzmgreptest$ echo *Ed_P*.xzm desktop
2ndEd_P-test-module.xzm Ed_P-test-module.xzm desktop
BASH replaces *Ed_P*.xzm with

Code: Select all

2ndEd_P-test-module.xzm Ed_P-test-module.xzm
and thus the script gets 3 parameters.
The error message should be more accurate, e.g.:

Code: Select all

Error: exactly two two parameters expected:
1st parameter: a path in which all modules should be searched or *one* module name
2nd parameter: the pattern to search for
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 5947
Joined: 06 Feb 2013, 22:12
Distribution: 4.0 & 5.0rc2 Cinnamon 64 ISOs
Location: Western NY, USA

lsxzmgrep

Post#9 by Ed_P » 21 Dec 2020, 19:11

I am referring to multiple modules with my name at the end. And it's not fair that the "." supports multiple files but not the "*". And yes I understand your explanation but it's still not fair. :x
Ed

User avatar
Rava
Contributor
Contributor
Posts: 2934
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc2 + 4.0 i586 XFCe
Location: Forests of Germany

lsxzmgrep

Post#10 by Rava » 21 Dec 2020, 22:11

Ed_P wrote:
21 Dec 2020, 19:11
I am referring to multiple modules with my name at the end. And it's not fair that the "." supports multiple files but not the "*". And yes I understand your explanation but it's still not fair. :x
You are a funny guy.

The way a script is coded is how it works. Coding is never about fairness.
If you want you can change the code to what you demand of it.

Two suggestions:
1) Use a loop with shift to loop through all parameters but the last. Presume all parameters but the last are either folders with modules, or individual module names, or a mix between folders and files. Expect the last parameter to be the search pattern.

2)
Reverse the order of parameters: Presume the first parameter being the search pattern and do a loop with shift for all following parameters. In this case all parameters but the first are either folders with modules, or individual module names, or a mix between folders and files as well.

Choose either approach 1) or 2)
Then start coding the loop with shift. For ease of debugging replace

Code: Select all

lsxzm ${module} | grep "$2" | sed -r "s#.+#>${module}\n&#"
with

Code: Select all

echo lsxzm ${module} grep "$2"
or a similar appropriate debugging info approach for the time being until the echo returns what you want the loop to do, then revert the echo only line back into the actual working line.

Done.

It's that simple. :magic:
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 5947
Joined: 06 Feb 2013, 22:12
Distribution: 4.0 & 5.0rc2 Cinnamon 64 ISOs
Location: Western NY, USA

lsxzmgrep

Post#11 by Ed_P » 22 Dec 2020, 05:24

:lol: So, I tried a varient of the lsxzmgrep command to find some string examples in the scripts I use.

Code: Select all

guest@porteus:~$ cat *.sh | grep "string" | sed -r "s#.+#>*.sh\n&#"
>*.sh
		if "${opt_arch_prefix}strings" "$_file" | grep -Eq '^Linux version '; then
>*.sh
	# also try harder with some kernels (such as Red Hat) that don't have ^Linux version before their version string
>*.sh
	kernel_version=$("${opt_arch_prefix}strings" "$kernel" 2>/dev/null | grep -E \
>*.sh
		# try even harder with some kernels (such as ARM) that split the release (uname -r) and version (uname -v) in 2 adjacent strings
>*.sh
		kernel_version=$("${opt_arch_prefix}strings" "$kernel" 2>/dev/null | grep -E -B1 '^#[0-9]+ .+ (19|20)[0-9][0-9]$' | tr "\n" " ")
>*.sh
	if ! command -v "${opt_arch_prefix}strings" >/dev/null 2>&1; then
>*.sh
		if "${opt_arch_prefix}strings" "$kernel" | grep -qw noibrs && "${opt_arch_prefix}strings" "$kernel" | grep -qw noibpb; then
>*.sh
		elif "${opt_arch_prefix}strings" "$kernel" | grep -q 'x86/pti:'; then
>*.sh
			pstatus yellow UNKNOWN "missing '${opt_arch_prefix}strings' tool, please install it, usually it's in the binutils package"
>*.sh
...
:shock: It needs work. :lol:
Ed

User avatar
Rava
Contributor
Contributor
Posts: 2934
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc2 + 4.0 i586 XFCe
Location: Forests of Germany

lsxzmgrep

Post#12 by Rava » 22 Dec 2020, 05:40

Ed_P wrote:
22 Dec 2020, 05:24
:shock: It needs work. :lol:
Try

Code: Select all

echo *.sh "string"
instead.

The two " | " from

Code: Select all

cat *.sh | grep "string" | sed -r "s#.+#>*.sh\n&#"
>*.sh
will only print positive results and omit negative ones. That is not optimal for debugging.

Also, the one line that does the grep on a module is not the issue to begin with, but having a loop with shift to process more than one parameter for a file or folder is.

My proposed echo line is just there to see if the outer loop with shift to process more than one parameter for a file or folder is working as intended.

Also from man bash
shift [n]

The positional parameters from n+1 ... are renamed to $1 ....
Parameters represented by the numbers $# down to $#-n+1 are unset. n must be a non-negative number less than or equal to $#. If n is 0, no parameters are changed. If n is not given, it is assumed to be 1. If n is greater than $#, the positional parameters are not changed. The return status is greater than zero if n is greater than $# or less than zero; otherwise 0.
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 5947
Joined: 06 Feb 2013, 22:12
Distribution: 4.0 & 5.0rc2 Cinnamon 64 ISOs
Location: Western NY, USA

lsxzmgrep

Post#13 by Ed_P » 02 Feb 2021, 23:45

This is what I ended up with for my lsshgrep.sh module.

Code: Select all

#! /bin/bash
# https://forum.porteus.org/viewtopic.php?f=140&t=8143

# https://forum.porteus.org/viewtopic.php?f=140&t=8143&p=68130
# https://forum.porteus.org/viewtopic.php?f=140&t=8143&p=68189

# the correct syntax for lsxzmgrep is "lsxzmgrep [path] [grep-pattern]" - Rava
# And [path] equal "." refers to the directory the command is executed in.
# thus "lsshgrep . Rava" searchs all .sh files in /home/guest/

for module in $(find $1 -type f -name "*.sh"); do
    cat ${module} | grep " $2 " | sed -r "s#.+#${module}: &#"
done
exit
:good:
Surprised that the find's sequence isn't in the same sequence as a ls *.sh command.
Ed

User avatar
Rava
Contributor
Contributor
Posts: 2934
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc2 + 4.0 i586 XFCe
Location: Forests of Germany

lsxzmgrep

Post#14 by Rava » 04 Feb 2021, 21:02

Just now I was trying to use my V2020-12-19 on i586 4.0 Porteus and it fails with this error:

Code: Select all

lsxzmgrep V2020-12-19
find: Arguments to -type should contain only one letter
Looks like Port 5.0rc-whatever version of find can handle more than one argument for -type, especially the used -type f,l


while the find of 4.0 cannot. :wall:

Added in 9 minutes 14 seconds:
Here the updated version for Port 4.0:

Code: Select all

#!/bin/bash
# https://forum.porteus.org/viewtopic.php?p=67979#p67979  brokenman
# https://forum.porteus.org/viewtopic.php?p=3522#p3522      82issa
# https://forum.porteus.org/viewtopic.php?p=80427#p80427  Ed_P
# https://forum.porteus.org/viewtopic.php?p=80384#p80384  &
#  https://forum.porteus.org/viewtopic.php?p=80432#p80432 &
#  https://forum.porteus.org/viewtopic.php?p=81323#p81323 Rava
VERSION=2021-02-04
echo -n $(tput sgr0)

echo $(tput bold)$(tput setaf 3)lsxzmgrep$(tput sgr0) V$(tput setaf 3)${VERSION}$(tput sgr0)

if [ $# -ne 2 ]; then
   echo $(tput bold)$(tput setaf 1)No xzm name and grep search pattern specified.$(tput sgr0)
   exit 1
fi

#4.0 error: find: Arguments to -type should contain only one letter
#for module in $(find "$1" -type f,l -name "*.xzm"); do
for module in $(find "$1" -name "*.xzm"); do
    lsxzm ${module} | grep "$2" | sed -r "s#.+#>${module}\n&#"
done
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 5947
Joined: 06 Feb 2013, 22:12
Distribution: 4.0 & 5.0rc2 Cinnamon 64 ISOs
Location: Western NY, USA

lsxzmgrep

Post#15 by Ed_P » 05 Feb 2021, 04:48

:o Yup

Code: Select all

guest@porteus:~$ uname -a
Linux porteus 4.16.3-porteus #1 SMP PREEMPT Sat Apr 21 12:42:52 Local time zone must be set-- x86_64 Intel(R) Core(TM) i3-6100U CPU @ 2.30GHz GenuineIntel GNU/Linux
guest@porteus:~$ find -type --help
find: Arguments to -type should contain only one letter
Not as clear in 5.0rc.

Code: Select all

guest@porteus:~$ uname -a
Linux porteus.example.net 5.10.12-porteus #1 SMP Sun Jan 31 10:29:01 UTC 2021 x86_64 Intel(R) Core(TM) i3-6100U CPU @ 2.30GHz GenuineIntel GNU/Linux
guest@porteus:~$ find -type --help
find: Unknown argument to -type: -
guest@porteus:~$ find -type help
find: Unknown argument to -type: h
guest@porteus:~$ find -type -h
find: Unknown argument to -type: -
guest@porteus:~$ find -type -help
find: Unknown argument to -type: -
guest@porteus:~$ 
But 2 character -type f,l definitely works.

Code: Select all

guest@porteus:/mnt/sda6/porteus5.0/Guest$ ./lsshgrep.sh . sed
./bootdev.sh:    BOOTMODE="ISO `cat /proc/cmdline | sed -e 's/^.*from=//' -e 's/ .*$//'`"
./bootdev.sh: Bold "ARCH:    " "`echo $MACHTYPE | sed -e 's/-.*$//'`"
./bootmode.sh:   ISO=`cat /proc/cmdline | sed -e 's/^.*from=//' -e 's/ .*$//'` 
./bootmode.sh:   sed -i s/dialog-warning.svg/alert.png/g /home/guest/Desktop/BootMode.desktop
./bootmode.sh:     sed -i s/alert.png/dialog-warning.svg/g /home/guest/Desktop/BootMode.desktop
./bootmode.sh: Bold "Changes: " "changes=`cat /proc/cmdline | sed -e 's/^.*changes=//' -e 's/ .*$//'`"
./Firefox81.sh: #sudo -S sed -i 's^=Qt;^=GTK;Qt;^' /usr/share/applications/keepassx.desktop
./Firefox81.sh:    sed -i 's^Default=t^Default=dxsqumip.default  #Default=t^'  /home/guest/.mozilla/firefox/profile.ini
./KeePassX.sh: sudo -S sed -i 's^keepassx %f^keepassx "/mnt/sda6/Users/Ed/My Utilities/KeePassX/"KeePass.kdbx^' /usr/share/applications/keepassx.desktop 
./KeePassX.sh: sudo -S sed -i 's^=Qt;^=GTK;Qt;^' /usr/share/applications/keepassx.desktop
./lsshgrep.sh:     cat ${module} | grep " $2 " | sed -r "s#.+#${module}: &#"
Ed

Post Reply