LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-27-2008, 10:44 PM   #1
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Rep: Reputation: 15
Bash scritping help


All,

Im new to bash scripting and i want to add a command line option where when a flag is used in the command it can omit some of the out put. I have a script that goes and lists all the disk partitions. I want to add to the script to omit what ever partition is chosen from the output.

Right now, the syntax and out put look like this:

bashscript.sh -H hostname

/local
/opt
/usr

New command needed:

bashscript.sh -H hostname -o /local

output:

/opt
/usr

I have getopts in this script so if that helps.

Thanks!
 
Old 09-27-2008, 11:02 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Use grep -v to strip out the argument(s) given to -o.

grep -v "$o_opt_arg"
 
Old 09-28-2008, 06:28 AM   #3
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
No -o was going to mean omit and the partition list after would be stripped out. In the script there getopts, which i understand is the best way to go. So there is a flag to change the output from all to just one specific partition.

Last edited by investmentbnker75; 10-01-2008 at 10:49 AM. Reason: change
 
Old 09-28-2008, 11:06 AM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Code:
$ echo -e '/local\n/opt\n/usr' 
/local
/opt
/usr

$ echo -e '/local\n/opt\n/usr' | grep -v /local
/opt
/usr

$ echo -e '/local\n/opt\n/usr' | egrep -v '/local|/opt'
/usr
Save the list of things passed to -o. The argument to -o will be a regular expression (like /local|/opt above). When it comes to output or process your final list, if there is an RE pattern saved (from -o), call {e}grep -v with the saved RE pattern on your data to be output.

For an example of this technique:

http://cis68b1.mikecappella.com/file...ars-params.pdf

Last edited by Mr. C.; 09-28-2008 at 11:10 AM.
 
Old 09-29-2008, 02:48 PM   #5
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
I didnt get that to work, let me post this script which is similar to what i was asking which i need to do the same thing to. I added -o flag to it to omit the tablespace, i just need the actual function to make it happen.

Last edited by investmentbnker75; 10-01-2008 at 10:48 AM.
 
Old 09-29-2008, 04:44 PM   #6
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
Moin,

please - if you post code, use the code tag (the "#" in the editor's menu) - as plain text nobody can read your code because no structure is visible.

thx
Jan
 
Old 09-29-2008, 08:13 PM   #7
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
And point out where you want help in the code. Bold the sections you want help with. I'm not in the mood tonight to try to guess where help is required. :-)
 
Old 09-29-2008, 09:31 PM   #8
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
Thanks MR. C. All your help is very much appreciated. I was able to resolve this issue

Last edited by investmentbnker75; 10-01-2008 at 10:49 AM. Reason: change
 
  


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
BASH -copy stdin to stdout (replace cat) (bash browser) gnashley Programming 4 07-21-2008 01:14 PM
Scritping - Point in the right direction eltnux Linux - Newbie 5 01-30-2008 02:00 PM
Bash Sleep vs crontab and bash serial port nutthick Programming 4 06-01-2006 02:42 AM
Bash: Print usage statement & exit; otherwise continue using Bash shorthand operators stefanlasiewski Programming 9 02-07-2006 05:20 PM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:29 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