Parse a single line file and store value.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse a single line file and store value.
# 8  
Old 02-24-2012
That is because only integer expressions can be use in test statements in any shell other than ksh93. Did you try earlier this suggestion?
Code:
if [ ${var2%%.*} -gt 6 ]; then

Code:
$ echo $var2
6.1
$ echo ${var2%%.*}
6

Otherwise you could use the utility bc ..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse for 2 numbers in large single line

Hi All, I am writing a script in which I need to gather 2 numbers for 'total' and 'successful'. The goal is to compare the two numbers and if they are not equal, rerun the task until all are successful. I'm thinking the best way will be with awk or sed, but I really don't know where to begin... (8 Replies)
Discussion started by: hburnswell
8 Replies

2. Shell Programming and Scripting

Need to parse the multiple definitions from a single line and assign

Hi, I need a help on my requirement that eg: NEED="TEST=Name WORK=Ps DEL=let" Here the definition can be n number, could anybody have an idea to get the output as, TEST=Name WORK=Ps DEL=let .. .. till the 'n' definitions listed. Any suggestions please..... Regards, ricky (6 Replies)
Discussion started by: ricky-row
6 Replies

3. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

4. Shell Programming and Scripting

How to store the file name in a single line??

hi, i have a variable, in which i am storing the file names that are present in the current directory. $ls -1 s1.txt s2.txt s3.txt $FILES=`ls -ltr | grep "^-" | awk '{print $NF}'` $echo $FILES s1.txt s2.txt s3.txt i want to store the files names in a single line in the variable... (7 Replies)
Discussion started by: Little
7 Replies

5. Shell Programming and Scripting

Execute sequential files and store data in single file

1)In a particualr path i have a set of inputfiles like path:/defaultmis/MonthlyLoads/INFA_EXPORT_022013/map* example: 1)map_de 2)map_cod 3)map_feg ........and so on in above path there wil be nearly 15 to 20 files starting with map and in other path i have another file input file... (4 Replies)
Discussion started by: katakamvivek
4 Replies

6. Shell Programming and Scripting

How to read a file line by line and store it in a variable to execute a program ?

Hello, I am quite new in shell scripting and I would like to write a little scritp to run a program on some parameters files. all my parameters files are in the same directory, so pick them up with ls *.para >>dirafter that I have a dir file like that: param1.para param2.para etc... I... (2 Replies)
Discussion started by: shadok
2 Replies

7. Shell Programming and Scripting

Parse config file and store the values in variables

Hi, I have a config file that has blank, commented lines. I need to escape commented lines, blank lines, parse the remaining lines and store them in variables or array. the config file contains the following lines. # config file # Define Oracle User ORA_USER=abcde ORA_PASS=xyzabc... (8 Replies)
Discussion started by: Lakshmi Chowdam
8 Replies

8. Shell Programming and Scripting

Parse text file in shell & store to variable

Hi, I need to parse a simple text file like below and store the word that starts with BR* to a variable say $BRno. I need to do this in sh script. NOTE: the length of the numbers following BR is in constant. And there is only 1 BRXXX in a file at a given time. .txt file: BR276828... (1 Reply)
Discussion started by: script2010
1 Replies

9. UNIX for Advanced & Expert Users

how do you parse 1 line at a time of file1 ie. line(n) each line into new file

File 1 <html>ta da....unique file name I want to give file=>343...</html> <html>da ta 234 </html> <html>pa da 542 </html> and so on... File 2 343 234 542 and so on, each line in File 1 one also corresponds with each line in File 2 I have tried several grep, sed, while .. read, do,... (4 Replies)
Discussion started by: web_developer
4 Replies

10. Shell Programming and Scripting

store the first line of a file in a variable

i have to store the files in a folder and assign a variable to the the files. (0 Replies)
Discussion started by: dineshr85
0 Replies
Login or Register to Ask a Question
GETOPTS(3)						  libbash getopts Library Manual						GETOPTS(3)

NAME
getopts -- libbash library for command line parameters parsing SYNOPSIS
$retval getopt_long <Instructions> <Parameters> DESCRIPTION
This is a documentation for libbash getopts library, that implements getopt_long function for bash(1). For documentation of bash getopts function, please see getopts(1) ( getopts(1posix) on some systems). Here is a table for reference: getopts(1) (or 1posix on some systems) implemented by bash getopts(3) implemented by libbash. getopt(1) implemented by getopt utils (part of util-linux) getopt_long(1) implemented by libbash and installed to section 1 instead of 3 to prevent collision with C man pages. getopt(3) implemented by GNU C library. getopt_long(3) implemented by GNU C library. I have also seen separate getopt utility which part of util-linux package. The getopt_long function parses the command line arguments. It uses Instructions as the rules for parsing the Parameters. The Instructions A string that specifies rules for parameters parsing. The instructions string is built of a group of independent instructions, separated by a white space. Each instruction must have the following structure: -<SingleLetter>|--<MultiLetter>-><VariableName>[:] This structure contains three parts: -<SingleLetter> This is the parameter single-letter sign. For example -h. --<MultiLetter> This is the parameter's corresponding multi-letter sign. For example --help. <VariableName>[:] This is the name of the variable that will contain the parameter value. For example: HELP. The Variable name can represent one of two variables types: Flag variable (not followed by ':') In this case, it will hold the value 1 if 'on' (i.e. was specified on command line) and will not be defined if 'off'. Value variable (followed by ':') In this case, the value it will hold is the string that was given as the next parameter in the Parameters string (Separated by white-space or '=' ). If input contains more then one instance of the considered command line option, an array of the given parameters will be set as the value of the variable. The Parameters The Parameters are simply the parameters you wish to parse. RETURN VALUE
This function returns a string that contains a set of variables definitions. In order to define the variables, this string should be given as a parameter to eval function. This value is returned in the variable $retval. EXAMPLES
Parse command line parameters looking for the flags -h | --help and -v | --version and for the value -p | --path : getopt_long '-h|--help->HELP -v|--version->VERSION -p|--path->PATH:' $* eval $retval In this example, for the parameters --help --path=/usr/ the variables that will be created are: HELP=1 PATH=/usr/ for the parameters --help --path=/usr --path=/bin the variables that will be created are: HELP=1 PATH=(/usr /bin) BUGS
Values must not contain the string `__getopts__'. This string will be parsed as a single white-space. A value should not start with an already defined multi-letter sign. If such a value exists, it will be treated as the equivalent singe-letter sign. This bug only accures when using a single-letter sign, or a multi-letter sign that are not followed by a `='. For example: If we have a script named `foo', and we parse the parameters `-d|--dir:' and `-f|--file:', then foo -d --file and foo --dir --file will not work foo --dir=--file will work. AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <gil@ran4.net> SEE ALSO
ldbash(1), getopt_long(1), getopts(1), getopt(1), libbash(1), getopt(3), getopt_long(3) Linux Epoch Linux