LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 02: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 03:29 AM.
 
Old 01-13-2011, 02:11 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,211

Rep: Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612Reputation: 1612
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, 02: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 03:29 AM.
 
0 members found this post helpful.
Old 01-13-2011, 02:16 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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, 08:13 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,565

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
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, 10:15 PM   #6
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,620

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
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 10:17 PM.
 
Old 01-19-2011, 12:49 PM   #7
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,211

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

 
Old 01-19-2011, 01:07 PM   #8
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,620

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
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, 01:32 PM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

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

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

All times are GMT -5. The time now is 04:30 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration