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.
# 1  
Old 02-24-2012
Parse a single line file and store value.

I have a single line file like this :

Average Fragmentation Quotient : 3.084121

Now I want to store the value which comes after ":" i,e 3.084121 into a variable.

And if this variable crosses above 6 i want to call another script...

can any one help me on this please ..

Last edited by vbe; 02-24-2012 at 10:03 AM.. Reason: typos...
# 2  
Old 02-24-2012
Code:
x=`awk '{print int($2)}' FS=: input_file`

if [ $x -gt 6 ]
then
   <call your script here>
fi

Guru.
# 3  
Old 02-24-2012
Hi Guru,

Thanks for the reply..

I want to make 3 more more updation like

1]f x is >0.6
2] less 7
3] less 0.8 ..
please suggest for same...
# 4  
Old 02-24-2012
Code:
var=$(cat infile)
var2=${var##* }

-or-

Code:
read x x x x var2 < infile

end then:
Code:
if [ ${var2%%.*} -gt 6 ]; then
  echo "do stuff with \$var2: $var2"
fi

In ksh93 you can just do this:
Code:
if [ $var2 -gt 6 ]; then


Last edited by Scrutinizer; 02-24-2012 at 10:52 AM..
# 5  
Old 02-24-2012
this dosent work for me ...
# 6  
Old 02-24-2012
What doesn't work for you?
# 7  
Old 02-24-2012
I am getting this error :

line 12: [: 0.6: integer expression expected
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