I tried inputting that command, but got told “command not found”.
Strange. You've essentially done the same commands before. e.g.
sudo dmesg|grep BluetoothTo deconstruct
sudo "dmesg |grep wlo1" > /somepath/sometextfile.txt you should have:
sudo gives you access to do (run) the given command under the su (superuser) access. (Or any other "substitute user" you can justify access to, to be correct, but superuser is the default substitute, so it's often thought of as that...)
sudo dmesg gets you access to all diagnostic messages (many that you don't want). You could run this on its own to get a mountain of (mostly) useless info, to test you've got this working. Except that we know this works.
sudo dmesg | grep FOO (optional spaces around ths pipe symbol, here for clarity only) takes the huge output and filters (with Global Regular Expression search and Print!) to show only lines with FOO in them. We know this works Ok, too.
sudo "dmesg | grep FOO" puts the pipe-and-grep as part of the superuser-doing, and I can't imagine that the su environment doesn't have access to grep, internally. (Especially as it should pass for use the relevent bits of Environment of your own shell, etc.) But perhaps try this smaller, but quoted, command (on some FOO that isn't too onerous) to check that this isn't the point of failure.
sudo "dmesg | grep FOO" > /filepath/etc/blah.de.blah is redirecting the output (that
sudo produces from both dmesg and piped-grep) to a file
blah.de.blah (at that
/filepath/etc location). This can fail if the filepath doesn't exist(/can't be written to) or the file there is unwritable-to for some reason, but it
won't be a "command not found".
(Well, it can in some situations of block device 'files', perhaps symbollically-linked to, but I doubt that's true here. Check by using
echo Test text > /filepath/etc/blah.de.blah (you are of course substituting for valid filepath+file, all along) to rule out this particular unlikely strangeness..)
I can't immediately think of a reason why
sudo dmesg | grep FOO > /filepath/etc/blah.de.blah would not work (sudo
just the dmesg, pipe that output through the grep (outside of sudo) and then further push that output to the file). We know that non-sudoed grep works (even if we're unsure about sudoed grep being valid), so it
should pipe nicely enough. But I've not got a *nix shell at hand, so this is just from memory. And deduction about how your environment works, which could be different from my expectations (even if I'm not mistaken in my own cases).
...this is more an opportunity to inform you(/people in general) of the potential beauty and utility of the command-line, for which you may already understand some of this anyway. And with the possibility of my own misassumptions/misrecollections being highlighted, because
I can't be 100% sure I'm right on this, not without hands on (an appropriate) keyboard to double-check with dry runs of my own.