Programming :: Parsing Unflagged Parameters In Bash Script?

Apr 6, 2010

I've searched online and found many examples using getopts, but nothing that clearly explains it use, nor any examples of what I'm trying to do. I have a script named "process". It can take from 0 to 3 different options. I'd like to be able to handle these options regardless of the order that they are entered.

Syntax:
process [-v] [-d #] [-h|-?] [string]
-v = verbose mode on
-d # = how deep to do the process, expecting a number parameter
-h or -? = show command usage
string = only process lines containing the specified string

[Code]..

View 5 Replies


ADVERTISEMENT

Programming :: Bash Script Sed -r -i And -e Parameters?

May 3, 2011

I have a bash script where I am replacing a date with a variable

Code:
variable="date"
sed -r "s/([0-9][0-9])/([0-9][0-9])/([0-9][0-9][0-9][0-9])/$variable/g" /path/to/file.txt
I have googled but cant find any info on what the -r, or sometimes I have seen -i and -e, after the "sed" I googled "sed parameters"

r appears to output the replaced date, but not change the original file. Usually using -i will change an original file for me. Does anyone know what the -i, -e, -r are about? A link to an explanation would be good, as I have been unable to find one in my searches.

View 10 Replies View Related

Programming :: Bash Script Position Parameter Does Is Not Parsing '$1'?

Apr 8, 2010

bash script:

Code:
$ bash --version
bash --version
GNU bash, version 3.1.17(2)-release (i486-slackware-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

Code:
[serv:]$ cat test.sh
#!/bin/bash

[Code]...

The question is, how to config it works through 'function cool {}' or cool() {} with position parameter

View 5 Replies View Related

Programming :: Bash Scripting - Parsing Text File By Character

Aug 11, 2009

Is there a way to process individual characters one-by-one from a text file in Bash, or is that hoping for a little too much from this lovable old clunker?

View 13 Replies View Related

Programming :: Passing Parameters From C Code To Bash Script

Apr 16, 2011

I get no print to stdout on screen from the C code.Does bash somehow block or mask it?I get print from bash. I get this error in the non-test bash script like: let "rdval = $rdstr"syntax error: operand expected (error token is " ")The let command prints rdval= but I presume this is due to the printf test statements getting in the way.I am getting no compile errors. Why does the C code not print the values specified?

View 2 Replies View Related

Programming :: Bash Variable Parsing / Extract And Put Into Variables Each Combination Of F1 And F2 In A Loop?

Oct 14, 2010

I have a bash variable where the content looks like this where ;f1; and ;f2; are delimiters:
;f1;field1value1;f2;field2 value1 ;f1;field1value2;f2;field2 value2 ;f1;field1value3;f2;field2 value3

So what I need is to extract and put into variables each combination of f1 and f2 in a loop to something like that:

#first pass of the loop I need:
f1=field1value1
f2=field2 value1

#second pass of the loop I need:
f1=field1value2
f2=field2 value2

# third pass of the loop I need:
f1=field1value3
f2=field2 value3

View 15 Replies View Related

Programming :: Parsing Text Files In Bash / Cant Seem To Read The Array Back?

May 29, 2011

PI'm trying to write a script to list all open ports in the MINIUNPND chain in iptables and use the procotol, port and destination ip to open ports on another router using upnpc.Here is the output of iptables -L MINIUPNPD

Code:
>iptables -L MINIUPNPD
Chain MINIUPNPD (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere 192.168.3.124 tcp dpt:19955
ACCEPT tcp -- anywhere 192.168.3.124 tcp dpt:20054
ACCEPT tcp -- anywhere 192.168.3.130 udp dpt:10654
ACCEPT tcp -- anywhere 192.168.3.121 tcp dpt:29955
code....

No matter what i do i cant seem to remove the first 4 characters from the MYPROT array to leave only the digits. Also i cant seem to read the array back???

I thought it would simply be a loop reading each line and passing the fields in variables, executing upnpc commands i need then moving to the next line of the file until it reached the EOF.

View 12 Replies View Related

General :: Parsing Strings Containing Bash Scripts?

Jan 15, 2010

fakeFile's contents :

Code:

blah $(date +%F) blah

fakeScript's contents :

Code:

while read line; do
echo $line
done < "fakeFile"

so here's the problem : is there any way to evaluate the fakeFile's contents (in the fakeScript), so that the term "$(date +%F)" (or any other bash script) in a string , translates to it's corresponding value ? (in this example , we want to have "blah current date" instead of " blah $(bash script) blah " )

View 9 Replies View Related

Ubuntu :: Parsing Web Data From Nagios (Bash Fu)?

Apr 27, 2011

We have a system called Skynet, which is basically a bunch of monitoring tools, including Nagios. What I want to do is output the status of 'critical' processes in conky. The conky part I'll worry about later (how hard can that be?), but I'm looking for some feedback on how I'm parsing the initial data. I figure that the simplest way to get the information is to query the cgi, then take what I need from the results...

Code:
wget -O - "http://user:pass@skynet/nagios/cgi-bin/status.cgi?status.cgi?host=all&servicestatustypes=16&hoststatustypes=3"| grep -i "<TD ALIGN=LEFT valign=center CLASS='statusBGCRITICAL'><A HREF='extinfo.cgi?type=2&host="

[Code]...

All I basically want is the server name and the process name, the above example giving server0/server1 and 'update status' as the service. How would you go about extracting merely these two pieces of information, bearing in mind that the server name and process are variable?

View 3 Replies View Related

Ubuntu :: Bash Parameters With-c Switch ?

Mar 11, 2011

From the man page for bash...

Quote:

If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0.

Code:

View 6 Replies View Related

General :: Get N-variable Parameters In Bash

Mar 21, 2011

I've a script that it's invoked with n-variable parameters. Here's an examples:

Code:
./myprogram.sh inputdir FIELD1 FIELD2 ... FIELDN outputfile In the script I would like to get the FIELD names that were passed.

View 4 Replies View Related

General :: Parsing Columns In Bash / Extract The First Set Of Numbers And Get Them To Appear Only Once?

Sep 28, 2009

as a result of a find command, i have

852065 72: /bin/gunzip
852065 72: /bin/gzip
852065 72: /bin/zcat

(the first column is inode number and the second is size if you're curious)

I want to be able to format it in a way such that:
852065 72:
/bin/gunzip
/bin/gzip
/bin/zcat

I know I can get the bottom half using awk- but I can't figure out how to extract the first set of numbers and get them to appear only once

View 9 Replies View Related

Ubuntu :: Pass Parameters To Bash Through Shellscript?

Mar 21, 2010

How do I pass file names as parameters to the shell through a script? I have installed 'wipe' from the repos and it is a shell based app. so I made a shellscript and put it in my script folder.

the normal usage of wipe is 'wipe -q /path/to/file' so if I were to make a shell script, right click on the file in question, and run the script on it, how to I permit the shell to wipe that file only, in other words pass it as a parameter. I think on windows it was the use of %1, such as. 'wipe -q %1' for example, which was simple enough. how to I achieve this with bash?

View 2 Replies View Related

General :: Bash And Php Parsing / Not Getting The Data To Output Correctly Into The Rows?

Oct 26, 2010

i am trying to get a script that i'm calling to have information from a sql populate into rows... but i'm not getting the data to output correctly into the rows. can someone please help?

<table>
<thead>
<tr>
<th>Name</th>
<th>Help</th>
<th>Folder</th>
code....

View 14 Replies View Related

General :: Check If Any Of The Parameters To A Bash Script Match A String?

Sep 8, 2010

I'm trying to write a script where I want to check if any of the parameters passed to a bash script match a string. The way I have it setup right now is if [ "$3" != "-disCopperBld" -a "$4" != "-disCopperBld" -a "$5" != "-disCopperBld" -a "$6" != "-disCopperBld"]but there might be a large number of parameters, so I was wondering if there is a better way to do this?EDIT:I tried this chunk of code out, and called the script with the option, -disableVenusBld, but it still prints out "Starting build". Am I doing something wrong?

while [ $# -ne 0 ]
do
arg="$1"

[code]....

View 3 Replies View Related

Ubuntu :: Parsing Textfiles And Passing Arguments In Bash To Preserve Tracker-tag Metadata

Sep 3, 2010

I'm at the bottom of the bash learning curve, looking up, hoping someone can toss me a line. I need to update tracker on my system but this will erase the metatag database I've been building up over the course of months for the purpose of indexing a news archive. So the solution seems to be, 1) save the output of tracker-tag to a text file for all relevant files within a directory, 2) upgrade tracker (since the version in the Ubuntu repositories is very much out of date) and then 3) use a script to parse the text file and pass appropriate arguments back to tracker-tag to rebuild the database. It sounds as though it ought to be simple enough, but I need a push in the right direction, which hopefully will not be off the cliff. Before I confuse my metaphors any further, here's what the text file looks like.

[Code]....

View 3 Replies View Related

Programming :: Parsing Log File With Awk?

Aug 31, 2009

I have logs files from freeradius that have looks as follows:

$ grep "Login incorrect (rlm_ldap: User not found" /var/log/radius/radiusd-inner-tunnel-20090831.log
Mon Aug 31 09:25:27 2009 : Auth: Login incorrect (rlm_ldap: User not found): [John Doe] (from client oficina port 0 via TLS tunnel)

[code]....

I use the following line to get the amount of users that don't exist on ldap:

Code:

grep "Login incorrect (rlm_ldap: User not found" /var/log/radius/radiusd-inner-tunnel-20090831.log | awk '{print $14}' | sort -fu | wc -l

Now, awk on line one for example parses [John Doe] and [Joon Williams] as "[John" and that it's not what I'd want. I mean how could I do for awk looks username field as closed between squared brackets?

View 1 Replies View Related

Programming :: Get Group Name From GID Without Parsing /etc/groups?

Sep 14, 2010

Is there a Linux system call that can be used to get the group name from the GID returned by stat()? I realize that I could parse /etc/groups (if my user had sufficient permissions).

View 3 Replies View Related

Programming :: Parsing S-Expressions In Python?

Feb 1, 2011

I've been loosely following this:http://norvig.com/lispy.htmlAnd I have a problem: the parsing function throws an array out of bounds exception. I thought that maybe I'm doing it wrong, so I copy and pasted the code from the page, and still the same error

View 2 Replies View Related

Programming :: Parsing Xml File From A C Program?

Mar 14, 2009

i wanted to know how can I pars a xml file (read data from xml file) and from C program.is there any function to do this for me in C.

View 1 Replies View Related

Programming :: Parsing XML Using Sax Parser In Java

Jul 7, 2011

I'll show the code first:

Code:

What I am after is to get the string text from the clip tags. But for now I just tested to see if it can finds the command tags and print something if it does. But it doesn't find it. Anyone knows why ?

Looks like the xml is not good, i test it with a xml validator:

Code:

View 1 Replies View Related

Programming :: Perl: Parsing A Log File?

Nov 9, 2010

I have a log file (test.log) starting & ending within dash (--) as below. I am looking to write a parser for test.log. This test.log file currently has single value for one Job ID but I wish to parse for repeated N values of different Job ID - Job, User, Queue, Dispatched Date, Dispatched Time, Completed Date, Completed Time, Hosts/Processor, CPU_T and TURNAROUND. I can either output this 10 values in another .log file or dump into cgi.

The selected parameters from test.log for parsing with above 10 attributes are -

--
Job <345010>
User <xyz>
Queue <gaussian>

[code]....

View 3 Replies View Related

Programming :: How To Run External Exe With Parameters

Mar 8, 2010

Specifically I'm trying to run xmacro from within a c program. If I were to run it from the terminal I would do it along the lines of Code: xmacroplay :0.0 < script_file.txt, but I want to run it from my c program. I'm fine with my c program running it from the terminal if that's possible and easier but I'm guessing there must be a better way.

View 3 Replies View Related

Programming :: Source Code On Email Parsing In C++ ?

May 11, 2010

Does anyone have source code on Email parsing in C++

View 1 Replies View Related

Programming :: Parsing And Storing Multiple Values Using 'awk'?

Jan 24, 2011

I have a variable in which the data is stored as below:

variable_test=0m0.001s 0m0.001s 0m0.001s 0m0.001s 0m0.001s 0m0.001s .....an so on.

There are lots of values in format like "3m1.057s" are stored in variable_test separated with an space between two such values. For exapmple, value is "3m1.057s" I need to save different parts of a value in three separate array variables such as the

var_hour=3
var_min=1
var_sec= 057

tell if this can be done using "awk". A "WHILE" loop might be used to separate and store theses values I guess?

View 1 Replies View Related

Programming :: Mail Log Parsing Script In Need Of Makeover?

May 30, 2011

I'm working on a script that will parse a mail machine's logs and print a list of email addresses in this format:

authen@domain.com | sender@domain | recipient@domain
exam
account1@domain1.com | sender2@domain2.com |

[code]...

View 2 Replies View Related

Programming :: Parsing Command Line Arguments In PHP?

Feb 1, 2010

I want to know how to get eg. the contents of a form on a webpage which has been passed to a server side PHP script, inside for example an array which I can read. I've been reading a ebook on PHP which as far as I can see doesn't cover this inside it.

View 1 Replies View Related

Programming :: Parsing Datetime Domain Names

Oct 25, 2010

I have spent lots of time trying to figure out how to parse the domain part of this file but am stuck.

How should this be approached:

Code:

Code:

The domains need to be parse at a maximum for 4 levels then the remainder will be put the last field.

View 3 Replies View Related

Programming :: Parsing Out Squid Access Log With Awk And Grep?

Apr 25, 2011

I'm trying to recreate a simple script I wrote to parse out the access.log to get a rough idea of websites that users are going to on our corp network. The issue I'm having is I want to pull out any line from access.log that ends in .com/ .org/ .net/ or whatever to only see what the user entered into the address bar and drop pictures, js's and everything else and log only this. so what I do is :awk '{print $8} | grep -e '[cong]|[ore]|[mgtv][/]'$ and nothing happens.I know there is an easier way to do this with awk alone,

View 8 Replies View Related

Programming :: URL With Parameters Containg Ampersand?

May 20, 2010

[URL]... The above url is generated by PHP code.

Code:
if($msg=="No capex advice")
echo " .. <a href="upload_capexadvice.php";
if($msg=="No purchase order")
echo " .. <a href="upload_purchaseorder.php";
if($msg=="No invoice")

[Code]...

I pass two parameters in a URL, s and q. I recently ran into the problem that the & in the value(aerial&satelitecity)causes a bit of trouble so I need to replace it. After some research I found that it needs to be replaced by %26. I've tried the standard PHP functions htmlspecialchars and htmlentities, but they translate to & Is there another function that I haven't found yet or must I write my own?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved