Sponsored Content
Top Forums Shell Programming and Scripting Assigning a value as a variable from a text file Post 302449769 by Scott on Tuesday 31st of August 2010 12:37:44 PM
Old 08-31-2010
Hi.

Code:
$ F=$(sed -n "/Freq *=/ s/.*= *//p" output.txt)

$ echo $F
1900

It could be a bit easier if your intended variable names matched those in the output.txt file. i.e.

Code:
$ cat Vars
while read LHS EQ RHS; do
  case "$LHS" in
    Freq|L) eval $LHS=\"$RHS\";;
  esac
done < output.txt

echo Freq is $Freq
echo L is $L

$ ./Vars
Freq is 1900
L is 159

But even if they don't:
Code:
while read LHS EQ RHS; do
  case "$LHS" in
    Freq) F="$RHS";;
    L) Len="$RHS";;
    ... etc
  esac
done < output.txt


Last edited by Scott; 08-31-2010 at 02:03 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading file and assigning that to Variable

I am missing something here, I have a file which contains only one line and that is either a number or character string. I am trying to read the file and assign that value to a variable and here it seems I am missing something and not getting the expected results... Here is the code : #!/bin/ksh... (2 Replies)
Discussion started by: Vaddadi
2 Replies

2. UNIX for Dummies Questions & Answers

Assigning value in a text file to a variable

Hi, I need to place a number located in a text file in a variable so I can perform if/then comparison. How would I go about doing this? Using A=awk '{print $2}' maintenance_date.tmp does not seem to work. Thanks (1 Reply)
Discussion started by: mojoman
1 Replies

3. UNIX for Dummies Questions & Answers

Searching a text file and assigning it to a variable

Hi Gurus, I am new to unix.I have a requirement as below I have text file like a.txt which contains a.txt hi hello process update status Ok to Proceed no issues good data arrangement My requirement here is i need to read the file and check for the words "OK to Proceed" and if... (2 Replies)
Discussion started by: pssandeep
2 Replies

4. Shell Programming and Scripting

Reading data from file and assigning to variable

I was trying to store the number of lines in a file and store it in a file.after that i want to store the information in a file to a variable which is further used in the if loop to check certain condition. #!/bin/bash cat <file> | wc -l > count.txt x="$count.txt"; i=10; if ; then cat... (10 Replies)
Discussion started by: sudhakaryadav
10 Replies

5. Shell Programming and Scripting

Removing a character from a variable and assigning it to another variable?

Hi folks. I have this variable called FirstIN that contains something like this: 001,002,003,004... I am trying to assign the content of this variable into ModifiedIN but with the following format : 001 002 003 004...(changing the commas for spaces) I thought about using sed but i am not... (17 Replies)
Discussion started by: Stephan
17 Replies

6. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

7. 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

8. Shell Programming and Scripting

Perl Help - Assigning variables to text file contents

I am looking to create a perl script which will take numbers from a simple text file, convert them from decimal to hex, and then rewrite those values in the file or create a new file with the hex numbers(whichever's easier). My text document for example would be something as simple as 1312... (6 Replies)
Discussion started by: samh785
6 Replies

9. Shell Programming and Scripting

assigning variable in txt file

Hi all, One of my txt file has common format like . And I need to manually assign variable to "/a/b/c/file1/txt" , which has common text before "Calculated summary file:". I wonder if I can use some command to do that for me, that it read the file and check for that comonn text and assign... (2 Replies)
Discussion started by: emily
2 Replies

10. Shell Programming and Scripting

Assigning file to a variable

Hi, I have a list of files in a directory. Each file has a .txt and a .log extension i.e. file.txt & file.log, file1.txt & file1.log etc. The file with the .log extension may not always exist alongside the file with the .txt extension. I need to copy the .txt file if there is a corresponding... (6 Replies)
Discussion started by: brunlea
6 Replies
TAU_MAPPING_OBJECT(3)						  TAU Mapping API					     TAU_MAPPING_OBJECT(3)

NAME
TAU_MAPPING_OBJECT - Declares a mapping object SYNOPSIS
C/C++: TAU_MAPPING_OBJECT(FunctionInfo FuncIdVar); DESCRIPTION
To create storage for an identifier associated with a higher level statement that is mapped using TAU_MAPPING, we use the TAU_MAPPING_OBJECT macro. For example, in the TAU_MAPPING example, the array expressions are created into objects of a class ExpressionKernel, and each statement is an object that is an instance of this class. To embed the identity of the statement we store the mapping object in a data field in this class. This is shown below: EXAMPLE
C/C++ : template<class LHS,class Op,class RHS,class EvalTag> class ExpressionKernel : public Pooma::Iterate_t { public: typedef ExpressionKernel<LHS,Op,RHS,EvalTag> This_t; // // Construct from an Expr. // Build the kernel that will evaluate the expression on the // given domain. // Acquire locks on the data referred to by the expression. // ExpressionKernel(const LHS&,const Op&,const RHS&, Pooma::Scheduler_t&); virtual ~ExpressionKernel(); // Do the loop. virtual void run(); private: // The expression we will evaluate. LHS lhs_m; Op op_m; RHS rhs_m; TAU_MAPPING_OBJECT(TauMapFI) }; SEE ALSO
TAU_MAPPING_CREATE(3), TAU_MAPPING_LINK(3), TAU_MAPPING_PROFILE(3) 08/31/2005 TAU_MAPPING_OBJECT(3)
All times are GMT -4. The time now is 08:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy