Trouble reading content of file from a variable

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trouble reading content of file from a variable
# 8  
Old 12-20-2013
Please use code tags as required by forum rules!

Originally Posted by Ravindra Swan
I mean

cp $a $b
echo `cat $b`
cat /ai/a.txt
cat /ai/b.txt both should give the same result set.
From what you show here, cat /ai/a.txt and cat /ai/b.txt ARE giving the same result unless there has been an error msg indicating that cp failed.
This User Gave Thanks to RudiC For This Post:
# 9  
Old 12-23-2013

Hi when i tried
cp $a $b

it is giving below error:
cp: cannot stat `$INF_COMRCLDATAMART_DML/ft_arnge_cred_risk_mtgt_fact.dml': No such file or directory

but when i tried
cp $INF_COMRCLDATAMART_DML/ft_arnge_cred_risk_mtgt_fact.dml $b

it is working fine and the contents are being copied correctly.
# 10  
Old 12-23-2013
So, are you saying that you have $a set as DML_FILE_NAME_ORIG1=$INF_COMRCLDATAMART_DML/ft_arnge_cred_risk_mtgt_fact.dml then?

This will not work. You are asking the shell to work with a file that isn't one. Which is the file you actually want to work with? I presume it's the one referred to by DML_FILE_NAME_ORIG1, i.e. $INF_COMRCLDATAMART_DML/ft_arnge_cred_risk_mtgt_fact.dml

This far down the chain of variables, the $ will just be a character. You need to get that interpreted before you call the cp command.

I would suggest that your logic is over complicated. Break it down to find a simpler way to refer to the file you need. If not, you will end up with a mess of:-
  • I want to use cp $a $b
  • $a refers to DML.....
  • $DML.... refers to $INF.... and a file.
It's just too messy.

Are the records in $AI_BIN/input.txt also variable names or variable assignments that you want to use? Can you share the format of that file so we can see what are trying to process.

Try to slim the code down to the minimal structure and just have a one record input file to your loop, then after pasting it into the thread along with the content of $AI_BIN/input.txt, can you run the script with ksh -x yourscript to illustrate where it is going. It might be obvious to you then, but if not I'm sure we can discuss it further.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Reading flat file content

is there any unix tools that can read the text files like through SQL queries? (ie in Hadoop, Impala DB support flat file query) (1 Reply)
Discussion started by: omykarshan
1 Replies

2. Shell Programming and Scripting

Trouble reading from a tab delimited excel file

So I have a file1.txt that is tab delimited: e.g. FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 9545641 123 "Neighbor and Labrador,Canada" 54895 'CANADA' 9456465 456 "Neighbor and Labrador,Canada" 54893 'CANADA' 8746512 789 "Neighbor and... (11 Replies)
Discussion started by: dan139
11 Replies

3. UNIX for Dummies Questions & Answers

Getting ls content into a file using variable

hi i just cant figure out how can i do this ls -lt > log.txt using $PWD what i mean is how can i get the ls command content into a file using $PWD variable? :confused: (4 Replies)
Discussion started by: chinababy
4 Replies

4. Shell Programming and Scripting

Trouble with variable assignment and reading in shell scripting

Hi, I have an inputfile with some table names in it. For ex: t_arnge t_profl t_fac I need a script which reads the line one by one and need to assign to some dynamic variable. If to explain the above example: i need some a=table_name1 table_name1=t_arnge in first time and... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies

5. Shell Programming and Scripting

Reading files under a folder and formatting content of each file

I have 'n' number of files in a folder .each file in the folder "myfolder" is having the content like. COLNAME ------------ AAAAAA BBBBBB CCCCCC DDDDDD ... ... ... ZZZZZZ 26 recrod(s) selected. My request is by reading each file in "myfolder" and format each file such a way... (18 Replies)
Discussion started by: rocking77
18 Replies

6. Shell Programming and Scripting

Trouble reading [noeol] file

cat can't show the last line of a file sftp transffered from Windows, because the last line is not ended with new line. Vi can show all line with warning I can append blank line in order for cat to show all lines, But is there a command to do this without modifying the file? > cat -A... (3 Replies)
Discussion started by: honglus
3 Replies

7. Shell Programming and Scripting

Reading content of a variable to create a new one?

Hello. I've written up a script, that populates a variable with a list of tapes returned from my library. For example: 701940L3,701941L3,701942L3,701943L3,701944L3,701945L3,701946L3,701947L3,701948L3 So now, the variable "TAPELIST" contains those numbers, delimited by commas. I'd like to... (6 Replies)
Discussion started by: Stephan
6 Replies

8. Shell Programming and Scripting

Problem in reading a file content

Hi, I am reading a file line by line using read line function of while loop. Each line contains 4 fields. I want to take these 4 values in 4 variables in each iteration so that i can use them in my script. The issue here is that my awk command is returning awkward results - Here is a sample line... (8 Replies)
Discussion started by: garman
8 Replies

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

10. UNIX for Advanced & Expert Users

Reading a file and sending mail based on content of the file

Hi Gurus, I am having an requirement. i have to read a list file which contains file names and send mail to different users based on the files in the list file. eg. if file a.txt exists then send a mail to simillary for b.txt,c.txt etc. Thanks for your help, Nimu (6 Replies)
Discussion started by: nimu1979
6 Replies
Login or Register to Ask a Question