The script should be able to do so without having to use lots of RAM.

Currently I cannot think of an elegant way to code it by myself.

Update
I also asked on https://stackoverflow.com and posted a working result in #9: search multiple modules
Code: Select all
for module in $(find $1 -type f -name "*.xzm"); do
lsxzm $module | grep "$2"
done
Code: Select all
ldd /usr/bin/mtpaint|grep not
libtiff.so.3 => not found
libjpeg.so.8 => not found
Code: Select all
root@porteus:/mnt/sda1/Porteus_4.0/porteus/base# lsxzmgrep . libtiff.so.3
/usr/lib64/libtiff.so.3
/usr/lib64/libtiff.so.3.9.7
Code: Select all
root@porteus:/mnt/sda1/Porteus_4.0/porteus/base# lsxzmgrep . libtiff.so.3
./example1.xzm: /usr/lib64/libtiff.so.3
./example1.xzm: /usr/lib64/libtiff.so.3.9.7
No, it won't.
Ok, I missed the part that this was done with Porteus 4.0's base where mtpaint works.Rava wrote: ↑21 Dec 2018, 20:47Put your code into a text executable named /usr/local/bin/lsxzmgrep . The result looks like so:Code: Select all
root@porteus:/mnt/sda1/Porteus_4.0/porteus/base# lsxzmgrep . libtiff.so.3 /usr/lib64/libtiff.so.3 /usr/lib64/libtiff.so.3.9.7
Code: Select all
for module in $(find $1 -type f -name "*.xzm"); do
echo " * " $module
lsxzm $module | grep "$2"
done
Indeed it is not ideal, but for now it works okay, since the module name is important, or else the result is more or less meaningless. "Yes, the files are in one of the 4 or 8 modules... but dunno in which ones" is sure not a result anyone wants.Ed_P wrote: ↑22 Dec 2018, 00:24As for brokenman's code this might yield something close to what you're looking for.Yes, it will display all module names and the name proceeding the grep hits is the module name you want.Code: Select all
for module in $(find $1 -type f -name "*.xzm"); do echo $module lsxzm $module | grep "$2" done
Code: Select all
root@porteus:/mnt/sda1/Porteus_4.0/porteus/base# lsxzmgrep . libtiff.so.3
./000-kernel.xzm
./001-core.xzm
/usr/lib64/libtiff.so.3
/usr/lib64/libtiff.so.3.9.7
./001-de-core_locales.xzm
./002-xorg.xzm
./003-xfce.xzm
./010-nvidia-304.137-k.4.16.3-x86_64-don.xzm
./991-usr_local_binV2018-06-25.xzm
Code: Select all
root 454656 2018-12-22 03:03 023-mtpaint-libs.xzm
Code: Select all
root@porteus:/# 1024calc 454656
444 KB
444.00 KB
root@porteus:/# cat /usr/local/bin/1024calc
#!/usr/bin/awk -f
BEGIN{ x = ARGV[1]
split("B KB MB GB TB PB",type)
for(i=5;y < 1;i--)
y = x / (2**(10*i))
print y " " type[i+2]
printf("%.2f %s\n",y,type[i+2])
}
Code: Select all
for module in $(find $1 -type f -name "*.xzm"); do
lsxzm ${module} | grep "$2" | sed -r "s/.+/${module}\n&/"
done
Code: Select all
/porteus/base$ lsxzmgrep . libtiff.so.3
sed: -e expression #1, char 10: number option to `s' command may not be zero
sed: -e expression #1, char 11: unknown option to `s'
sed: -e expression #1, char 11: unknown option to `s'
sed: -e expression #1, char 11: unknown option to `s'
sed: -e expression #1, char 11: unknown option to `s'
sed: -e expression #1, char 11: unknown option to `s'
sed: -e expression #1, char 11: unknown option to `s'
sed: -e expression #1, char 11: unknown option to `s'
sed: -e expression #1, char 11: unknown option to `s'
Code: Select all
#!/bin/bash
for module in $(find $1 -type f -name "*.xzm"); do
result=$(lsxzm $module | grep "$2")
if [ $? -eq 0 ]; then
# grep returned OK, write out results
echo $module
echo "$result"
fi
done
"I"https://stackoverflow.com/questions/53918069/live-linux-grep-script-only-print-positive-results wrote:I try to code a bash 4 (or sh, if that's possible) script that does the following: 1st parameter: the path to the compressed modules to search, could be "." 2nd the search pattern to look for
Or even better, do it like grep would do it when searching multiple files, print the module name with added ": " in front of the "grep result" list:
Code: Select all
grep -Hn
Hmm I got an update on stackoverflow:brokenman wrote: ↑26 Dec 2018, 13:47This will show you the filename and the line number.Code: Select all
grep -Hn
Code: Select all
for module in $(find $1 -type f -name "*.xzm"); do
lsxzm ${module} | grep "$2" | sed -r "s#.+#${module}\n&#"
done
Code: Select all
/porteus/base# /tmp/lsxzmgrep2 . output_dummy
./002-xorg.xzm
/usr/lib64/mpg123/output_dummy.so
Code: Select all
for module in $(find $1 -type f -name "*.xzm"); do
lsxzm ${module} | grep -Hn "$2" | sed -r "s#.+#${module}\n&#"
done
Code: Select all
/porteus/base# /tmp/lsxzmgrep2 . output_dummy
./002-xorg.xzm
(standard input):2562:/usr/lib64/mpg123/output_dummy.so
Code: Select all
#!/bin/bash
for module in $(find $1 -type f -name "*.xzm"); do
lsxzm ${module} | grep "$2" | sed -r "s#.+#${module}\n&#"
done
Code: Select all
root@porteus:/tmp/64bit-kernel4.20.2# lsxzmgrep initrd
find: ‘initrd’: No such file or directory
root@porteus:/tmp/64bit-kernel4.20.2# lsxzmgrep . initrd
./06-crippled_sources-4.20.2-64bit.xzm
/usr/src/linux-4.20.2/include/config/blk/dev/initrd.h
./06-crippled_sources-4.20.2-64bit.xzm
/usr/src/linux-4.20.2/include/linux/initrd.h
./06-crippled_sources-4.20.2-64bit.xzm
/usr/src/linux-4.20.2/init/.do_mounts_initrd.o.cmd
./06-crippled_sources-4.20.2-64bit.xzm
/usr/src/linux-4.20.2/init/do_mounts_initrd.c
./06-crippled_sources-4.20.2-64bit.xzm
/usr/src/linux-4.20.2/tools/testing/selftests/rcutorture/doc/initrd.txt
How can a user give a command the wrong syntax without calling the command? Please do explain how this is possible.