Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to call variables from a file to the scripting file? Post 303043124 by TestKing on Sunday 19th of January 2020 08:57:01 AM
Old 01-19-2020
How to call variables from a file to the scripting file?

Let say I have a file with variables (Test1.txt)
In Test1.txt file, it consists of
Code:
Tom is a boy
Jim is a dog

In the other scripting file (RunTest1.sh), I have
Code:
#!/bin/ksh
filename = /directory/Test1.txt
cat $filename
for i in $filename
do 
     print $i
done

I managed to call variables from the another file to the executing file, but the content from the another file would not show unless cat command is used...... I tried using for loop to print out each value, but it gets the directory instead....How do I assign a parameter to take the value from the other file? I would like the result to be shown as below....

Code:
Subject  Verb   Object
Tom      is          a boy
Jim       is          a dog

Moderator's Comments:
Mod Comment Please do wrap your samples in CODE TAGS as per forum rules.

Last edited by TestKing; 01-19-2020 at 10:57 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

file activity (open/closed) file descriptor info using KORN shell scripting

I am trying to find a way to check the current status of a file. Such as some cron job processes are dependent on the completion of others. if a file is currently being accessed / modified or simply open state I will wait until it is done being processed before attempting the next process on that... (3 Replies)
Discussion started by: Gary Dunn
3 Replies

2. Shell Programming and Scripting

reading from a file and pass as variables and ignore # in the file

file.txt contains ------------------ sat1 1300 #sat2 2400 sat3 sat4 500 sat5 I need to write a shell script that will output like the below #output sat1.ksh 1300 sat3.ksh sat4.ksh 500 sat5.ksh my try ------- (4 Replies)
Discussion started by: konark
4 Replies

3. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

4. Shell Programming and Scripting

How to call a batch file in Make file?

Hii I wanna call a batch file from a make file. Doesn't work , what is the procedure to do this.? Any idea thanks:eek: (2 Replies)
Discussion started by: krishnampkkm
2 Replies

5. Shell Programming and Scripting

Read file and for each line replace two variables, add strings and save output in another file

Hi All, I have a file, let's call it "info.tmp" that contains data like this .. ABC123456 PCX333445 BCD789833 I need to read "info.tmp" and for each line add strings in a way that the final output is put /logs/ua/dummy.trigger 'AAA00001.FTP.XXX.BLA03A01.xxxxxx(+1)' where XXX... (5 Replies)
Discussion started by: Andy_ARG
5 Replies

6. Shell Programming and Scripting

Bash: Reading a file and assigning variables from file

I have a file that has four values on each line and I'd like to give each column a variable name and then use those values in each step of a loop. In bash, I believe you could use a while loop to do this or possibly a cat command, but I am super new to programming and I'm having trouble decoding... (2 Replies)
Discussion started by: ccorder22
2 Replies

7. Shell Programming and Scripting

How to search and append words in the same file using unix scripting file operations

Hi , I have a file myhost.txt which contains below, 127.0.0.1 localhost 1.17.1.5 atrpx958 11.17.10.11 atrpx958zone nsybhost I need to append words only after "atrpx958" like 'myhost' and 'libhost' and not after atrpx958zone. How to search the word atrpx958(which is hostname) only,... (5 Replies)
Discussion started by: gsreeni
5 Replies

8. Shell Programming and Scripting

Shell scripting - need to arrange the columns from multiple file into a single file

Hi friends please help me on below, i have 5 files like below file1 is x 10 y 20 z 15 file2 is x 100 z 245 file3 is y 78 z 23 file4 is x 100 (3 Replies)
Discussion started by: siva kumar
3 Replies

9. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

10. Shell Programming and Scripting

Need Help: Shell script to call sql session with variables stored in .txt file

Hi, I need help in writing a shell script which can read data from a text file (Cancel_ID.txt) and then calls sqlplus session (Cancel.sql) with the first line parameter of the text file ("0322600453") till all rows are not completed. ... (4 Replies)
Discussion started by: Khan28
4 Replies
Devel::GraphVizProf(3pm)				User Contributed Perl Documentation				  Devel::GraphVizProf(3pm)

NAME
Devel::GraphVizProf - per-line Perl profiler (with graph output) SYNOPSIS
perl -d:GraphVizProf test.pl > test.dot dot -Tpng test.dot > test.png DESCRIPTION
NOTE: This module is a hack of Devel::SmallProf by Ted Ashton. It has been modified by Leon Brocard to produce output for GraphViz, but otherwise the only thing I have done is change the name. I hope to get my patches put into the main Devel::SmallProf code eventually, or alternatively read the output of Devel::SmallProf. Anyway, the normal documentation, which you can probably ignore, follows. The Devel::GraphVizProf profiler is focused on the time taken for a program run on a line-by-line basis. It is intended to be as "small" in terms of impact on the speed and memory usage of the profiled program as possible and also in terms of being simple to use. Those statistics are placed in the file smallprof.out in the following format: <num> <time> <ctime> <line>:<text> where <num> is the number of times that the line was executed, <time> is the amount of "wall time" (time according the the clock on the wall vs. cpu time) spent executing it, <ctime> is the amount of cpu time expended on it and <line> and <text> are the line number and the actual text of the executed line (read from the file). The package uses the debugging hooks in Perl and thus needs the -d switch, so to profile test.pl, use the command: perl5 -d:GraphVizProf test.pl Once the script is done, the statistics in smallprof.out can be sorted to show which lines took the most time. The output can be sorted to find which lines take the longest, either with the sort command: sort -k 2nr,2 smallprof.out | less or a perl script: open(PROF,"smallprof.out"); @sorted = sort {(split(/s+/,$b))[2] <=> (split(/s+/,$a))[2]} <PROF>; close PROF; print join('',@sorted); NOTES
o The "wall time" readings come from Time::HiRes and are reasonably useful, at least on my system. The cpu times come from the 'times' built-in and the granularity is not necessarily as small as with the wall time. On some systems this column may be useful. On others it may not. o GraphVizProf does attempt to make up for its shortcomings by subtracting a small amount from each timing (null time compensation). This should help somewhat with the accuracy. o GraphVizProf depends on the Time::HiRes package to do its timings. It claims to require version 1.20, but may work with earlier versions, depending on your platform. OPTIONS
GraphVizProf has 3 variables which can be used during your script to affect what gets profiled. o If you do not wish to see lines which were never called, set the variable "$DB::drop_zeros = 1". With "drop_zeros" set, GraphVizProf can be used for basic coverage analysis. o To turn off profiling for a time, insert a "$DB::profile = 0" into your code (profiling may be turned back on with "$DB::profile = 1"). All of the time between profiling being turned off and back on again will be lumped together and reported on the "$DB::profile = 0" line. This can be used to summarize a subroutine call or a chunk of code. o To only profile code in a certain package, set the %DB::packages array. For example, to see only the code in packages "main" and "Test1", do this: %DB::packages = ( 'main' => 1, 'Test1' => 1 ); o These variables can be put in a file called .smallprof in the current directory. For example, a .smallprof containing $DB::drop_zeros = 1; $DB::profile = 0; will set GraphVizProf to not report lines which are never touched for any file profiled in that directory and will set profiling off initially (presumably to be turned on only for a small portion of code). INSTALLATION
Just the usual perl Makefile.PL make make test make install and should install fine via the CPAN module. BUGS
Subroutine calls are currently not under the control of %DB::packages. This should not be a great inconvenience in general. The handling of evals is bad news. This is due to Perl's handling of evals under the -d flag. For certain evals, caller() returns '(eval n)' for the filename and for others it doesn't. For some of those which it does, the array "@{'_<filename'}" contains the code of the eval. For others it doesn't. Sometime, when I've an extra tuit or two, I'll figure out why and how I can compensate for this. Comments, advice and questions are welcome. If you see inefficent stuff in this module and have a better way, please let me know. AUTHOR
Ted Ashton <ashted@southern.edu> GraphVizProf was developed from code originally posted to usenet by Philippe Verdret <philippe.verdret@sonovision-itep.fr>. Special thanks to Geoffrey Broadwell <habusan2@sprynet.com> for his assistance on the Win32 platform and to Philippe for his patient assistance in testing and debugging. Copyright (c) 1997 Ted Ashton This module is free software and can be redistributed and/or modified under the same terms as Perl itself. SEE ALSO
Devel::DProf, Time::HiRes. perl v5.14.2 2012-04-02 Devel::GraphVizProf(3pm)
All times are GMT -4. The time now is 08:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy