[SOLVED] Basis SED script won't run from cli using '\' characters
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
sed -n \
-e '/^root/ p' \
-e '/^nobody/ p' \
/etc/passwd
did you try as single line?
change to, pretty sure there should be no space after regex
Code:
sed -n \
-e '/^root/p' \
-e '/^nobody/p' \
/etc/passwd
EDIT: I just tried as you wrote, and it worked perfect, same as my suggestion. I was able to do this with a regular user with no privileges. Are you able to cat /etc/passwd with no problems.
First, you have to be root to run this, since root has access to /etc/passwd, and not a regular user account.
You should not have to be root. I created a new user with no privileges, and was able to see ouput of this command. Same concept I can nano /etc/passwd as any user just can't write.
Quote:
Originally Posted by JockVSJock
This is how I wrote it up, and no spaces after '\'
Code:
sed -n \
> -e '/^root/ p' \
> -e '/^nobody/ p' \
> /etc/passwd
This happened to me when I first copied your code. Didn't dawn on me to mention that.
Quote:
Originally Posted by JockVSJock
Notice after the first line the ">" character appears. Something to do with the stdout, correct?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.