LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-13-2011, 01:06 PM   #1
Checksumfail
LQ Newbie
 
Registered: Jan 2011
Posts: 12

Rep: Reputation: 0
Bash Script -


removed

Last edited by Checksumfail; 01-18-2011 at 02:29 AM.
 
Old 01-13-2011, 01:11 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Quote:
command=`ps aux | grep root | sed -n '1,13p;13g'`
echo $command >> somefile.out
You can try this
 
1 members found this post helpful.
Old 01-13-2011, 01:16 PM   #3
Checksumfail
LQ Newbie
 
Registered: Jan 2011
Posts: 12

Original Poster
Rep: Reputation: 0
removed

Last edited by Checksumfail; 01-18-2011 at 02:29 AM.
 
0 members found this post helpful.
Old 01-13-2011, 01:16 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Code:
"ps aux | grep root | sed -n '1,13p;13g'" >> $HOME/ShellScriptsRemote/output.txt
Why you embed the command in double quotes? The shell interprets the whole pipe as a single command name and obviously cannot find it. Remove the (unnecessary) quotes and the trick is done.
 
Old 01-13-2011, 07:13 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I am curious what the point of the '13g' is for in this particular sed?

Also if you want extra marks in your assignment you might consider the following:

1. grep is not required as sed could provide the functionality for you

2. Whether using grep or sed to find search item you may wish to consider are you searching for a user or that word anywhere on the line??
 
Old 01-13-2011, 09:15 PM   #6
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Hi,

I agree with grail. Unless you shortened your actual sed command before you posted it here, the '13g' does not accomplish anything. It simply tells sed to copy the hold buffer to your pattern space. Since you have not put anything in in your hold buffer you simply 'delete' your pattern space. This is also pointless because line #13 has already been printed by the previous command: '1,13p'
You can speed up your sed by
sed -e '13 q'
This will print line 1-13 by default and quit when it encounters line 13.

Last edited by crts; 01-13-2011 at 09:17 PM.
 
Old 01-19-2011, 11:49 AM   #7
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
According to your signature, that sed line should be wrapped in CODE tags.

 
Old 01-19-2011, 12:07 PM   #8
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by szboardstretcher View Post
According to your signature, that sed line should be wrapped in CODE tags.

Does not strictly apply for one-liners
 
Old 01-19-2011, 12:32 PM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by Checksumfail View Post
removed
How to trash a thread... congratulations!
 
Old 01-19-2011, 01:38 PM   #10
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
It was probably homework and he didn't want his teacher to find it.
 
  


Reply



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
Variables and Mkvextract in a bash script and a good resource for bash help? gohmifune Linux - General 9 04-13-2011 08:37 AM
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 06:00 AM

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

All times are GMT -5. The time now is 08:50 PM.

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