Sponsored Content
Top Forums Shell Programming and Scripting Search file for string and store last result to variable Post 302491622 by gwr on Thursday 27th of January 2011 11:16:34 PM
Old 01-28-2011
Search file for string and store last result to variable

Hi,

I'm trying to search a text file for a string: "energy(sigma->0)=". To do so, I executed the grep command, which returned many matches, for example:

Code:
  energy without entropy =     -112.16486170  energy(sigma->0) =     -112.16520778
  energy without entropy =     -112.16488936  energy(sigma->0) =     -112.16522827
  energy  without entropy=     -112.164889  energy(sigma->0) =     -112.165228

What I want to do is store the grep results to a variable (var1), then get the very last number in the very last string result (the last number in var1), and store it to a second variable (var2) for later use in bash.

Alternatively, if there is a better command than grep that can automatically return only the last search hit in a given file, that would be even better.

Any assistance would be greatly appreciated!

gwr

Last edited by Franklin52; 01-28-2011 at 03:32 AM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to store query multiple result in shell script variable(Array)

:) Suppose,I have one table A. Table A have one column. Table A have 10 rows. I want this 10 rows store into shell script variable. like #!/bin/ksh v_shell_var=Hi here in call oracle , through loop How can I store table A's 10 rows into v_shell_var (Shell Script Array). Regards, Div (4 Replies)
Discussion started by: div_Neev
4 Replies

2. Shell Programming and Scripting

Prase a file and store and result to an array

Dear all, I have a file having the following formats: ThreadFail=Web1=1234 ThreadFail=Web2=2345 ThreadFail=Web3=12 ConnectionFail=DB1=11 ConnectionFail=DB2=22 The number of lines will be different from every time . How can I parse the file and store the result to an a array inside... (6 Replies)
Discussion started by: youareapkman
6 Replies

3. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

4. Shell Programming and Scripting

How to search for string and return binary result?

Hi, I have a problem that I am sure someone will know the answer to. Currently I have a script which returns a binary output if it finds a certain search string (in this case relating to a DRBD cluster) as follows: searchstring="cs:Connected st:Primary/Secondary ds:UpToDate/UpToDate" && echo... (3 Replies)
Discussion started by: almightybunghol
3 Replies

5. Programming

how to store string in variable

sorry i'm newbies c programer how to store string to variable with value flexible. example int hh=1; ---> value flexible 1,2,3,4,5; int xx=1; ---> value flexible 1,2,3,4,5; char test="value=%d and value=%d",hh,xx; --> not working char test2="value2=%d and value2=%d",hh,xx; --> not... (1 Reply)
Discussion started by: slackman
1 Replies

6. Shell Programming and Scripting

How to store result of grep into a variable?

In a directory i have a file *output* whose contents are changing for every simulation. zgrep "trace file is" *output* | zgrep g o/p: trace file is Int_01.1352176388z4f56ec33.0.trace.gz I want to extract "Int_01.1352176388z4f56ec33.0.trace.gz" from the above result into a variable. i... (2 Replies)
Discussion started by: twistedpair
2 Replies

7. Shell Programming and Scripting

Extract a string from a file and store it in variable

Hi, I've a file ImageSizeDetails.txt with the following contents: Image Name: swncd 01.10.00.04 Created: Wed Jan 9 14:05:48 2013 Image Type: ARM Linux Multi-File Image (gzip compressed) Data Size: 7351011 Bytes = 7178.72 kB = 7.01 MB Load Address: 00008000 Entry Point: ... (6 Replies)
Discussion started by: Parameswaran
6 Replies

8. Shell Programming and Scripting

Store result variable

Friends have the following problem: cat $PATH_DAT/mr.txt | nawk 'BEGIN { CantPnt=0; NumReg=0; FS="|" } { NumReg++ CantPnt=CantPnt+int($2) } END{ printf... (5 Replies)
Discussion started by: tricampeon81
5 Replies

9. Shell Programming and Scripting

Bash to store result in variable for other lines in script to use

I can not figure out how to capture the $filename variable store by the bash. #!/bin/bash # oldest folder stored as variable for analysis, version log created, and quality indicators matched to run dir=/home/cmccabe/Desktop/NGS/test find "$dir" -maxdepth 1 -mindepth 1 -type d -printf... (5 Replies)
Discussion started by: cmccabe
5 Replies

10. UNIX for Beginners Questions & Answers

Need help with how to search a file for a variable string and delete that line

Hi, I have a working script. It does what I am intending it to but a bit confused whether the sed part is supposed to be working or not. Further down is the script with the sed part that should have been working but not and the grep -v part which is the workaround that I am using at the... (10 Replies)
Discussion started by: newbie_01
10 Replies
LQR_CARVER_GET_ENERGY(3)				     LqR library API reference					  LQR_CARVER_GET_ENERGY(3)

NAME
lqr_carver_get_energy, lqr_carver_get_true_energy, lqr_carver_get_energy_image - get the energy map for a LqrCarver object SYNOPSIS
#include <lqr.h> LqrRetVal lqr_carver_get_energy(LqrCarver* carver, gfloat * buffer, gint orientation); SYNOPSIS
#include <lqr.h> LqrRetVal lqr_carver_get_true_energy(LqrCarver* carver, gfloat * buffer, gint orientation); SYNOPSIS
#include <lqr.h> LqrRetVal lqr_carver_get_energy(LqrCarver* carver, void * buffer, gint orientation, LqrColDepth col_depth, LqrImageType image_type); DESCRIPTION
The function lqr_carver_get_energy writes the energy map of the LqrCarver object pointed to by carver to the given buffer, in a format suitable for plotting: all values are in the range between 0 and 1, and the true values are mapped nonlinearly and stretched on this whole range, so that the differences between the middle values are enhanced with respect to very high or very low values. The orientation parameter must be either 0 to get the energy map used for horizontal scalings, or 1 to get the map for vertical scalings. The buffer must be allocated by the user before calling this function, and its size must be at least width * height, where width and height are the current width and height of the carver. The energy values are ordered by row first, then by column. The outcome will include the effect of the bias added to the carver, if any. This function can be called over non-initialised LqrCarver objects, e.g. to provide previews on the effect of different energy functions, but it can also be invoked at any later time. Note, however, that in this latter case the carver could be flattened if necessary, therefore the function invocation is potentially destructive of the internal visibiliy map. The function lqr_carvet_get_true_energy is identical to the previous one, but the resulting buffer will contain the true energy, not scaled nor shifted. The function lqr_carver_get_energy_image is very similar to the function lqr_carveR_get_energy, but it can be used to fill directly an image buffer of the format specified through the additional parameters col_depth and image_type (see LqrColDepth(3) and LqrImageType(3)). The buffer must be passed as void*, but it must point to a memory area with sufficient allocated space for the chosen image type and colour depth. The image type cannot be LQR_CUSTOM_IMAGE. For any choice of the parameters describing the image, the resulting buffer will hold a greyscale image, ranging from black (lowest energy) to white (highest energy). The opacity (alpha) will be set to 1, if present. All the information will be stored in the black channel in LQR_CMYK_IMAGE and LQR_CMYKA_IMAGE image types. RETURN VALUES
The return values follow the Liquid Rescale library signalling system. The function lqr_carver_get_energy_image will return an error if image_type is LQR_CUSTOM_IMAGE. SEE ALSO
lqr_carver_set_energy_function_builtin(3), lqr_carver_set_energy_function(3), lqr_carver_bias_add(3) COPYRIGHT
Copyright (C) 2007-2009 Carlo Baldassi LqR library 0.4.1 API (3:1:3) 10 Maj 2009 LQR_CARVER_GET_ENERGY(3)
All times are GMT -4. The time now is 04:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy