Sponsored Content
Top Forums Shell Programming and Scripting Awk: Assigning a variable to be the value of FNR at a certain line Post 302961880 by ThomasP on Saturday 5th of December 2015 03:40:04 PM
Old 12-05-2015
Ah yes see that's the problem, the 'overlap' NFR will always be several (100+) lines before the oldte==te2 (energy equilibrium) NFR, because of how the simulation works.

So if the some_var still gets evaluated as =NFR when I print it at the end
f.e. print(some_var) then i'll have the wrong value. On the other hand if it only gets evaluated as being = an integer (a previous NFR in this case) than I'm golden.

An array wouldn't help me since I can't know which line I need, that's the whole point of getting the NFR value at that point.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with assigning output of grep + awk to a variable

Hi All, I am getting the output for the following command when i run it on the unix console. --------------------------- grep `whoami` /etc/passwd | awk '{print ($1);}' | cut -d ":" -f3 ---------------------------- But i made it into a script and tried to print the variable, its... (5 Replies)
Discussion started by: meheretoknow
5 Replies

2. Shell Programming and Scripting

Assigning Variable to AWK statement

Hi, The following command runs on in the Korn shell prompt. however i want to output the value of this to a variable. Can anyone provide a solution? echo 'ABC,DEF,"G,HI,J",KLM,"MNi,O"'| awk -F "\"" '{for(i=1;i<=NF;i++){if(i%2)gsub("\,","~^~",$i)}}1' (2 Replies)
Discussion started by: ladarlsan
2 Replies

3. UNIX for Dummies Questions & Answers

Assigning the output of a command to a variable, where there may be >1 line returned?

Hello I am using unix CLI commands for the Synergy CM software. The command basically searches for a folder ID and returns the names of the projects the folder sits in. The result is assigned to a variable: FIND_USE=`ccm folder -fu -u -f "%name"-"%version" ${FOLDER_ID}` When the command... (6 Replies)
Discussion started by: Glyn_Mo
6 Replies

4. Shell Programming and Scripting

Assigning last line to variable in expect

As part of an expect script, I have to convert a strange user ID to a conventional UNIX ID. To do this, I read the contents of a file and do a little awk magic. Here's that bit of the expect script: send "awk 'NF == 10 && \$NF == strange_user_id {print \$(NF-2)}' file_with_my_info\r" expect... (0 Replies)
Discussion started by: treesloth
0 Replies

5. Shell Programming and Scripting

how to Read a file and assigning each line to a variable?

Friends, I have a file output.txt with values as below: 092307135717 061910135717 I want to know how to read this file and then assign each value to a variable. say like var1=092307135717 var2=061910135717 So that I can use this VAR1 and Var2 in the shell script for further processing.... (3 Replies)
Discussion started by: shyamaladevi
3 Replies

6. Shell Programming and Scripting

problem in assigning substr to a variable inside awk

Hi All, I have a fixed-width datafile from which i need to extract value/string starting from some position to the specified length in each of the lines. awk '{print substr($0,x,y)}' datafile --- is working fine but awk 'BEGIN{a=0}{a=substr($0,x,y);print $a}' datafile ---is giving... (3 Replies)
Discussion started by: loggedin.ksh
3 Replies

7. Shell Programming and Scripting

Assigning a value to variable through awk

I am trying to assign a value to a variable thru awk and I am having a lot of problem with it. Pls see the code snippet. The one in RED is the actual code. Other lines are the op created by the system. As you can see from the data, I was expecting an output of DG010 SDS FILE for FILE_NAME... (6 Replies)
Discussion started by: vskr72
6 Replies

8. Shell Programming and Scripting

Assigning output from awk to variable

I have a script whose contents are as below result= awk 's=100 END {print s }' echo "The result is" $result The desired output is The result is 100 My script is running without exiting and i am also not getting the desired output. Please help (5 Replies)
Discussion started by: bk_12345
5 Replies

9. Shell Programming and Scripting

Assigning Variable to Line Numer in nl

hi, i'm creating a little menu for some users. i'm running the command: du -a /apps | sort -n -r | head -n 10 | nl i then get the top 10 files by size in the /apps directory the output is like this: 1 101415752 /apps 2 89188064 /apps/userA 3 74521335 ... (1 Reply)
Discussion started by: horhif
1 Replies

10. UNIX for Dummies Questions & Answers

Tcsh command for assigning output of awk to variable

Hi I have a text file with 2 values and I am trying to assign each value to a variable and then write those to text files. So if the textfile is data.txt with 2 values x and y I want to assign mean=x, and stdev=y and then write these out in text files alongwith the id ($id has already been... (6 Replies)
Discussion started by: violin
6 Replies
EV(1)							      General Commands Manual							     EV(1)

NAME
ev - evaluate expressions SYNOPSIS
ev 'expr' .. DESCRIPTION
Ev evaluates expressions given on the command line, and sends the results to the standard output, one per line. An expression contains real numbers, function calls, and the following operators: + - * / ^ Operators are evaluated left to right, except '^', which is right associative. Powers have the highest precedence; multiplication and division are evaluated before addition and subtraction. Expressions can be grouped with parentheses. All values are double precision real. The following library of functions is available: if(cond, then, else) if cond is greater than zero, then is evaluated, otherwise else is evaluated. select(N, a1, a2, ..) return aN (N is rounded to the nearest integer). If N is zero, the number of available arguments is returned. rand(x) compute a random number between 0 and 1 based on x. floor(x) return largest integer not greater than x. ceil(x) return smallest integer not less than x. sqrt(x) return square root of x. exp(x) compute e to the power of x (e approx = 2.718281828). log(x) compute the logarithm of x to the base e. log10(x) compute the logarithm of x to the base 10. sin(x), cos(x), tan(x) trigonometric functions. asin(x), acos(x), atan(x) inverse trigonometric functions. atan2(y, x) inverse tangent of y/x (range -pi to pi). EXAMPLE
To pass the square root of two and the sine of .5 to a program: program `ev 'sqrt(2)' 'sin(.5)'` AUTHOR
Greg Ward SEE ALSO
icalc(1), rcalc(1) RADIANCE
10/28/96 EV(1)
All times are GMT -4. The time now is 11:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy