08-23-2012
Develop a simple command line parser
I want to develop a simple command line parser so that then I can print the values of different options :tions.
-analyze
-filename<fileName>
Via man pages I got to know getopt command would be used.
Buut how to use it.. how to encrypt this in a perl script..
grateful if u could help
10 More Discussions You Might Find Interesting
1. Programming
hey peeps
i need to allow a user to input a line and then my job is to separate that line into tokens and print out what each command is. my question here is, if eg: 'ls > aifle' is entered as the input line, you would separate it and get three tokens: token 1 would be 'ls', token 2 '>' and... (0 Replies)
Discussion started by: mile1982
0 Replies
2. UNIX for Dummies Questions & Answers
hai friend,
I am new to linux... I have to develop C program using unix command and i know the SYSTEM command.. But i need other then SYSTEM comand, plz send me the sample code....
Thank you..
sundar (1 Reply)
Discussion started by: sundar.lsr
1 Replies
3. Shell Programming and Scripting
I would like to capture output from two commands to a test file on the same line...
I want to get a file with all Applications and the Version of it...here are the two commands I use to get the output.
To get Application list I use
ls -1 /Applications/ |grep .app >>... (3 Replies)
Discussion started by: elbombillo
3 Replies
4. Shell Programming and Scripting
Hi Guys,
If want to change the string "09-06-11" to "11062009", i can only think use split to get the array@, the ,,, then restructure the sequence.
Is there a simple line to do that? :o
Thanks
-----Post Update-----
@file_e_tmp = split('-', $ARGV);
$file_date_e =... (6 Replies)
Discussion started by: jimmy_y
6 Replies
5. UNIX for Dummies Questions & Answers
Hi,
How would one send an email from the command line. Just a simple email. I used mailx -s "test" address@server.domain then hit enter.
Nothing happens then, I hit Ctrl + C twice, then I can start a new command again.
Any help? Tips? I did read up on this, but the examples is much more... (2 Replies)
Discussion started by: McGuywer
2 Replies
6. Shell Programming and Scripting
input1
a_a a/a 10 100
a1 a_a 20 200
b1 b_b 30 300
input2
a_a a/a xxx yyy
a1 a1 lll ppp
b1 b_b kkk ooo
output
a_a a/a 10 100 xxx yyy (2 Replies)
Discussion started by: ruby_sgp
2 Replies
7. Infrastructure Monitoring
Hi:
I use the snmpget command everyday. And Im getting tire of writing the same line evertime I have to verify something.
Example of the line:
snmpget -c DreamTeam dal2-hr2 ifAlias.227
The .227 its the circuit interface and also its variable; could be any other number depending on the... (13 Replies)
Discussion started by: javygonx
13 Replies
8. Shell Programming and Scripting
I have a really basic expect script which I call from php. I works fine when I run the php from the shell, but from the web it appears as if the output buffer gets chopped and never gets all of the contents.
php script: (runexpect.php)
<?php... (7 Replies)
Discussion started by: jacksona2
7 Replies
9. UNIX for Dummies Questions & Answers
Hello
I'm searching some kind of example (or ready-made solution, but I don't really want it, because I want to learn awk more), to make something like a parser in awk for something like this (I put example, because I don't really know how to explain this):
line1=1
line2=0
line3=1... (23 Replies)
Discussion started by: jormung
23 Replies
10. Shell Programming and Scripting
my requirement is,
consider a file output
cat output
blah sdjfhjkd jsdfhjksdh
sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf
hellow there
this doesnt look good
et cetc etc
etcetera
i want to replace a line of line number 4 ("this doesnt look good") with some other line
... (3 Replies)
Discussion started by: vivek d r
3 Replies
getopt(1) General Commands Manual getopt(1)
NAME
getopt - Parses command line flags and arguments
SYNOPSIS
getopt format tokens
DESCRIPTION
The getopt command is used to parse a list of tokens using a format that specifies expected flags and arguments. A flag is a single ASCII
letter and, when followed by a : (colon), is expected to take a modifying argument that may or may not be separated from it by one or more
tabs or spaces. (You can include multi-byte characters in arguments, but not as flag letters.)
The getopt command completes processing when it has read all tokens or when it encounters the special token -- (double dash). It then out-
puts the processed flags, a --, and any remaining tokens.
If a token fails to match a flag, getopt writes a message to standard error.
NOTES
In the csh, use the following command to run getopt:
set argv=`getopt flag_string $*`
EXAMPLES
The following is an example of the use of getopt in a skeleton shell script to parse options:
#!/bin/sh # parse command line into arguments set -- `getopt a:bc $*` # check result of parsing if [ $? != 0 ] then
exit 1 fi while [ $1 != -- ] do
case $1 in
-a) # set up the -a flag
AFLG=1
AARG=$2
shift;;
-b) # set up the -b flag
BFLG=1;;
-c) # set up the -c flag
CFLG=1;;
esac
shift # next flag done shift # skip double dash # now do the work . . .
The following are all equivalent arguments to the script:
-a ARG -b -c -- A B C -a ARG -bc -- A B C -aARG -b -c -- A B C -b -c -a ARG -- A B C
SEE ALSO
Commands: sh(1)
Functions: getopt(3)
getopt(1)