Reading text from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading text from a file
# 8  
Old 05-10-2007
+ init
+ entry=GARBAGE
+ 0< /stuartTemp/ReleaseScripts/SQL/toRelease.txt
+ read record
+ + expr substr @database 2 999
expr: syntax error
entry=
+ read record
+ eval [${#[*]}]=femotest
./release.sh[16]: [${#[*]}]=femotest: bad substitution

I was thinking that perhaps my version does not support substr in expr expressions, how can i check this?

Last edited by LiquidChild; 05-10-2007 at 11:13 AM..
# 9  
Old 05-10-2007
You can test your expr command with :
Code:
expr substr abcdef 2 3    # Gives bcd
expr substr @DATABASE 2 3 # Gives DAT
expr substr @DATABASE 2 999 # Gives DATABASE

The expr command can be replaced by cut :
Code:
entry=`echo "$record" | cut -c2-`


Jean-Pierre.
# 10  
Old 05-11-2007
Thanks aigles, the cut option worked.

When i done the expr option, it gave the same error at the terminal window, however what I find weird is that the substr option appears in the man pages.

aww well, thanks again.
# 11  
Old 05-30-2007
Hi

I am still working on this problem, well actually just getting back round to it, anyway I have implemented the arrays as suggested above but instead of having the output as above, i.e. with line: eval echo \"${array}[${i}]=\${${array}[${i}]}\"

I just want to place each value within the array into a variable.

Currently my code is:

for arrays in packageSpecs packageBodies procedures triggers functions views sqlScripts
do
eval count=\${#${arrays}[*]}

if [ $count -eq 0 ]
then
echo "${arrays}: Nothing to be verified"
else
counter=0

while [ $counter -lt $count ]
do
eval echo \"\${${arrays}[${counter}]}\"

fileToVerify=eval \${${arrays}[${counter}]}\

echo "Verifing: $fileToVerify"

counter=$counter+1
done
fi


But this does not work as expected, I know its the line: fileToVerify=eval \${${arrays}[${counter}]}\ that gives me issues and have tried different ways to write this line looking at what agiles done above, can someone please tell me what I am doing wrong? Thanks
# 12  
Old 05-30-2007
Try to change :
Code:
fileToVerify=eval \${${arrays}[${counter}]}\

by
Code:
eval fileToVerify=\${${arrays}[${counter}]}

Please use [CODE] tag...


Jean-Pierre.
# 13  
Old 05-30-2007
Thanks (again), worked a treat.

Sorry never seen the [code] tags, will use next time Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to write in other language in text/xml file by reading english text/xml file using C++?

Hello Team, I have 2 files.one contains english text and another contains Japanese. so i have to read english text and replace the text with Japanesh text in third file. Basically, I need a help to write japanese language in text/xml file.I heard wstring does this.Not sure how do i write... (2 Replies)
Discussion started by: SA_Palani
2 Replies

2. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

3. Shell Programming and Scripting

Reading colums from a text file

Hi all, I have a text file that has (4) columns. There are about 300 lines on this file. It is a plain text file. I am looking to write a simple script that will read each line from the file and generate another text file. The file looks something like this: These are the columns: ... (4 Replies)
Discussion started by: adamw
4 Replies

4. Shell Programming and Scripting

Reading the text file for particular format

Hi All, Need your help!! I have particular host file with below format: 172.34.45.67 Host1 Host2 134.45.56.67 Host3 Host4 Host5 I need shell script snippet which read this file and change the format of the file to the below format 172.34.45.67 Host1 172.34.45.67 ... (9 Replies)
Discussion started by: sharsour
9 Replies

5. Shell Programming and Scripting

Reading a value from another text file

I am having a text file best = 100 genre = 75 group = 53 . . and so on I need to read those values (100,75,53,...) from my shell script. I have to do the same function for all the variables. So in my script i used for loop to do the same. for { a=best b=100 } Video tutorial on... (3 Replies)
Discussion started by: kishorekumar87
3 Replies

6. Programming

reading a text file in c++

hello all , im trying to read a text file and display its contents. While i got the code running and the output was displayed perfectly for sometime , i started getting Abort(core dump) error . Am i missing something here ? im using HP-UX. #include <iostream.h> #include <fstream.h> #include... (1 Reply)
Discussion started by: vishy_85
1 Replies

7. Shell Programming and Scripting

Help with Reading Text from file

Hello, I am having a tough time reading data from an input text file. The input file has lines of data which is comma seperated. Each line represents a record/row, but unfortunately the data in the individual column/fields have spaces and `cat filename`is not returning entire line ( to read... (4 Replies)
Discussion started by: yajaykumar
4 Replies

8. UNIX for Dummies Questions & Answers

Help with reading text file

How can i have a while loop as follows while read inputline do <task> done < name_list and also store the values (delimited) on each line to temp variables so as to print them on screen as follows while read inputline do set name | cut -d "," -f1 name_list # #i know this is not... (1 Reply)
Discussion started by: bilal05
1 Replies

9. Shell Programming and Scripting

Reading from Text file.....

Hi Im MZ.... please help me with my requirements..... Requirement: I have a text file named information.txt which contains information about Oracle Instances, I want to fetch data's from that text file and want to display an output using shell script. Explanation : i.e. when I execute that... (0 Replies)
Discussion started by: user__user3110
0 Replies

10. Shell Programming and Scripting

reading text file

I have a text file with 50 munbers. I wanna read these numbers and append "@yahoo.com" and send emails to them using shell scripting.......... How do i read the inetegres from the text file. (1 Reply)
Discussion started by: jaan
1 Replies
Login or Register to Ask a Question