18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
How to retrieve a specific line from a file
hi ,
can any one help me , how to read a single or specific line from a file.
i'am using _readFile(" path.txt");
but it is reading the complete data .
can any one help me , how to read a single or specific line from a file.
i'am using _readFile(" path.txt");
but it is reading the complete data .
This discussion has been closed.
Comments
_readFile will read all the contents of the file into the variable designated by you. You need to use pattern matching/regular expression capabilities of javascript to extract the required line from your file. If possible you can post the content your text file and the required text to be extracted.
Regards,
Pankaj.
Thanks for the response,
my file consists of Username,Qualification,Age which is stored in d "D:\\details.txt".
now how can i retrieve the Qualification from that file.
can you send in what format it is available in the file. i mean how the data is seperated in the text file. its comma separated, tab delimited etc.
any more information will help.
The file is written like this:
name,Qualification,Age
user1,B.sc,21
User2,M.sc,22
user3,B.tech,23
Here is a function to retrieve text from a file using regular expression. It is not a very fine piece of code (Didn't have much time). Its just to give you a direction to think upon.
Still finding it difficult to use this to set a variable to the value returned by the function. It throws some error. I used older version of sahi for this (non-rhino).
I hope Narayan can throw some light why it throws error if we try to set a variable to the value returned by the function below. I observed this behavior when ever I try to user regular expression functions like match(), substring() etc. Below is the text file i used; This one searches for the qualification of the user2 only but its returning it with the surrounding commas as well. you will have to biuld a more refined regular expression for your purpose.
It will need to be worked upon to make it work for you but I hope that will help you somewhat
Regards,
Pankaj.
_alert(match());
This piece of code will return you the qualification of the username passed to the function match() as long as the format of the text file is that provided in my previous message.
Regards,
Pankaj.
_sahi.setServerVar('\$qual', match("user2"));
ReferenceError: match is not defined
Anybody have solution ?
This is an old post from 2008. Please create a new post, tell us what your requirement is, what you tried and what failed.
If you have not already done so, please read the posting guidelines: http://sahi.co.in/forums/viewtopic.php?id=1640
Regards,
Narayan