LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 06-13-2016, 06:07 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Basis SED script won't run from cli using '\' characters


Experimenting with SED and trying to get this rum from the CLI:

Code:
sed -n \
-e '/^root/ p' \ 
-e '/^nobody/ p' \ 
/etc/passwd
Once entering the final line of /etc/passwd and pressing return, nothing is returned to the screen.

I have to press ctrl + c to break out of this.

I realize the \ allows me to start a new line. However I'm not understanding why this isn't working.

thanks
 
Old 06-13-2016, 07:09 PM   #2
dab1414
Member
 
Registered: May 2011
Location: OK, USA
Distribution: Slackware 14.1_64
Posts: 76

Rep: Reputation: 52
Quote:
Originally Posted by JockVSJock View Post

Code:
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.

Last edited by dab1414; 06-13-2016 at 08:06 PM.
 
Old 06-13-2016, 07:53 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Make sure you don't put a space after the \
 
1 members found this post helpful.
Old 06-13-2016, 08:34 PM   #4
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
I got it to work. IMO, the example was a bad.

First, you have to be root to run this, since root has access to /etc/passwd, and not a regular user account.

This is how I wrote it up, and no spaces after '\'

Code:
sed -n \
> -e '/^root/ p' \ 
> -e '/^nobody/ p' \
> /etc/passwd
Notice after the first line the ">" character appears. Something to do with the stdout, correct?
 
Old 06-13-2016, 09:27 PM   #5
dab1414
Member
 
Registered: May 2011
Location: OK, USA
Distribution: Slackware 14.1_64
Posts: 76

Rep: Reputation: 52
Quote:
Originally Posted by JockVSJock View Post
I got it to work. IMO, the example was a bad.

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 View Post
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 View Post
Notice after the first line the ">" character appears. Something to do with the stdout, correct?
Check this out, helped me understand it better. Basically second line is PS2 prompt.
https://linuxconfig.org/bash-prompt-basics
 
1 members found this post helpful.
  


Reply

Tags
sed



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using sed in bash script to serach and replace special characters, and text PoltoX Programming 6 08-14-2013 10:25 PM
Script won't run in crontab rastellig Linux - Software 2 03-25-2009 09:18 AM
php script will not run correctly as cron, fine from cli dtra Linux - Software 2 12-22-2005 07:21 AM
Script won't run at boot bugsbunny Slackware - Installation 6 04-19-2004 04:26 PM
Yet another configure script that won't run gauge73 Linux - Newbie 1 02-14-2004 02:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration