Sponsored Content
Top Forums Shell Programming and Scripting reading variable value from a file Post 302365809 by ahmad.diab on Wednesday 28th of October 2009 05:50:48 AM
Old 10-28-2009
Code:-

Code:
nawk -F"(=| )" '
(FNR==NR){a[$1]=$2 ; next}
{r=($1 in a) ?  $1"-->"a[$1] :  $1 ; print r}
' b.txt a.txt

BR
 

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. Shell Programming and Scripting

Reading variable from file variable values

Hi, Here is the output of lpstat. I would like to read value of Queue which is(abxxxxb1)and status that is DOWN in first line. i dont care what is in second line. any one can help me.thanks Queue Dev Status Job Files User PP % Blks Cp Rnk ------- ----- ---------... (5 Replies)
Discussion started by: sagii
5 Replies

3. Shell Programming and Scripting

How to get the modified value of variable outside the while loop reading from a file

Hi Friends , Sorry if this is a repeated question , The input file contains 5 lines , so the the values of the variables i and count should b i=5; count=15 but the variables are not updating , the value of variables showing i=0 and count =0 only.:mad: can any1 help me please. (11 Replies)
Discussion started by: babusek
11 Replies

4. Shell Programming and Scripting

reading the whole line from a file into a variable

Hi, I am doing : while read line do printf "%s\n" ${line} done <datafile.txt but I am not getting each single line from the data file assigned to the variable line (but only tokens/fields at a time). I also tried while IFS= read -r lineI want the whole line assigned or read into the... (2 Replies)
Discussion started by: shri_nath
2 Replies

5. UNIX for Dummies Questions & Answers

Reading a variable from file

Hi, I have a situation where I need to read a variable from another file. But the problem is that the variable in the other file is starting with $. E.g. file1: $var1=out temp_ss.sh: . file1 echo "Print : $var1" It works fine if the file1 is having var1=out (note that it is... (6 Replies)
Discussion started by: shash
6 Replies

6. Shell Programming and Scripting

Reading a file with while into variable and using in another process

I would appreciate some help, please. I have a file cutshellb.txt, which contains four report names (but it could be any number from 1 to x. The report suffix is not necessarily consecutive: report3785 report3786 report3787 report3788 I have a shell script which attempts to read the... (3 Replies)
Discussion started by: Dicloflex
3 Replies

7. Shell Programming and Scripting

Reading a variable from parameter file

HI all, I have a parameter file with entries like $$Name =Abhinav $$CUTOFF_DATE = 11/11/2209 I am reading a variable from this file using a awk command like : var2=`awk -F"" "/CUTOFF_DATE/{f=$1;}{print f;}" InputFIleName` but facing an error like awk: cmd. line:1:... (3 Replies)
Discussion started by: abhinav192
3 Replies

8. Shell Programming and Scripting

Reading from a file and storing it in a variable

Hi folks, I'm using bash and would like to do the following. I would like to read some values from the file and store it in the variable and use it. My file is 1.txt and its contents are VERSION=5.6 UPDATE=4 I would like to read "5.6" and "4" and store it in a variable in shell... (6 Replies)
Discussion started by: scriptfriend
6 Replies

9. Shell Programming and Scripting

Reading from a File and Using as an Input variable

I need to know how the the string constant from Input File should be read and provide as input data for the script . INPUT FILE CONST VARIABLE myname=/root/dir/syslog/myname1 myname=/root/dir/syslog/myname2 myname=/root/dir/syslog/myname3 urname=/root/dir/syslog/urname1... (6 Replies)
Discussion started by: baraghun
6 Replies

10. Shell Programming and Scripting

Trouble reading content of file from a variable

Hi , i have a parameter which has path of a file. Now i need to have another parameter with the content of that file. I tried the belwo script , can any one please help. I dont want to use cat command to read. Can we do it with out using cat command. while read line do... (9 Replies)
Discussion started by: Ravindra Swan
9 Replies
FINFO_OPEN(3)								 1							     FINFO_OPEN(3)

finfo_open - Create a new fileinfo resource

       Procedural style

SYNOPSIS
resource finfo_open NULL ([int $options = FILEINFO_NONE], [string $magic_file]) DESCRIPTION
Object oriented style (constructor): finfo::__construct NULL ([int $options = FILEINFO_NONE], [string $magic_file]) This function opens a magic database and returns its resource. PARAMETERS
o $options - One or disjunction of more Fileinfo constants. o $magic_file - Name of a magic database file, usually something like /path/to/magic.mime. If not specified, the MAGIC environment variable is used. If the environment variable isn't set, then PHP's bundled magic database will be used. Passing NULL or an empty string will be equivalent to the default value. RETURN VALUES
(Procedural style only) Returns a magic database resource on success or FALSE on failure. NOTES
Warning The expected magic database format changed in PHP 5.3.11 and 5.4.1. Due to this, the internal magic database was upgraded. This mostly effects code where an external magic database is used: reading an older magic file will now fail. Also, some textual repre- sentations of the mime types has changed, for instance for PHP would be "PHP script, ASCII text" instead of "PHP script text" returned. Note Generally, using the bundled magic database (by leaving $magic_file and the MAGIC environment variables unset) is the best course of action unless you specifically need a custom magic database. EXAMPLES
Example #1 Object oriented style <?php $finfo = new finfo(FILEINFO_MIME, "/usr/share/misc/magic"); // return mime type ala mimetype extension /* get mime-type for a specific file */ $filename = "/usr/local/something.txt"; echo $finfo->file($filename); ?> Example #2 Procedural style <?php $finfo = finfo_open(FILEINFO_MIME, "/usr/share/misc/magic"); // return mime type ala mimetype extension if (!$finfo) { echo "Opening fileinfo database failed"; exit(); } /* get mime-type for a specific file */ $filename = "/usr/local/something.txt"; echo finfo_file($finfo, $filename); /* close connection */ finfo_close($finfo); ?> The above example will output: text/plain; charset=us-ascii SEE ALSO
finfo_close(3). PHP Documentation Group FINFO_OPEN(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