Sponsored Content
Top Forums Shell Programming and Scripting help me ...problem in reading a file Post 302077060 by msridh on Monday 19th of June 2006 06:46:16 AM
Old 06-19-2006
Hi,

Try following

#!/bin/ksh

cat <filename> | while read record
do

echo $record

done

Best Regards,
Sridhar M

Quote:
Originally Posted by brkavi_in
hi,
while reading a file line by line

# name of the script is scriptrd

while read line
do
echo $line
done


while executing
bash$ ./scriptrd
if i give the input as
*

the output is like it displays the contents of the current directory

i jus wanted it to print as *


can anybody help me in this?
 

10 More Discussions You Might Find Interesting

1. Programming

problem in reading file using fread

Hi All, These are the two ways i tried to read file but i getting work with second one not with the first. char buf; // Defining space for buf ctrlfnum = fopen(filename_arr.control_fname,"r"); 1) n = fread(buf,sizeof(buf),1,ctrlfnum); ============== (not works) 2) n =... (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

2. Shell Programming and Scripting

File reading problem via shell script

Hi, Data file named parameter contains : DB=y Alter_def.sql Create_abc.sql SQL=y database.sql my_data.sql To read this file I use var_sql=$(awk -F= '$1 == "SQL" { print $2 }' parameter.txt) if then sql_f_name=`grep "\.sql" parameter.txt` echo $sql_f_name fi (2 Replies)
Discussion started by: Dip
2 Replies

3. Shell Programming and Scripting

problem in reading a file

i need to read record by record i use script #!/bin/ksh for i in 'cat filename' do echo $1 done but i dont get expected result i just get filename echoed on screen (4 Replies)
Discussion started by: er_zeeshan05
4 Replies

4. UNIX for Dummies Questions & Answers

Intermittent problem reading from an input file.

First of all thanks to all for the good post, and the great site. I'm a noob, but I've been able to learna a lot by checking past posts. I haven't been able to make sense of a problem that I've been working on for a while, hopefully someone can help me out. The script I wrote telnets into... (7 Replies)
Discussion started by: Wallygooo32
7 Replies

5. Shell Programming and Scripting

problem in reading a record from the file

Hi Guys, I need to check whether the last column is RP, If so, then i have to second column and pass it to a select statement as sonid and fetch the value to a variable and run it. This has to be done till the last column is RW. value Fatherid sonid topid ... (8 Replies)
Discussion started by: mac4rfree
8 Replies

6. Shell Programming and Scripting

Problem with reading from a properties file

Hi, i have a properties file a.prop where entry is like PROCESS_IDX=0 Now in my shell schript i am doing like this. #!/bin/sh . a.prop .............. -....................... while read line do # tokenize the string by ",". var=(`echo $line | tr ',' ' '`) echo $PROCESS_IDX -->... (6 Replies)
Discussion started by: sailaja_80
6 Replies

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

8. Shell Programming and Scripting

Problem in reading a file

Hi Guys, I am having a file which does not have any name when i do a ls -l -rw-r--r-- 1 dctrdat1 dctrdata 35 Feb 09 08:04 -rw-r--r-- 1 dctrdat1 dctrdata 11961 Feb 08 06:40 DAI_data.txt Now i want to see what is inside that file. Can you please let me know how to read... (9 Replies)
Discussion started by: mac4rfree
9 Replies

9. Shell Programming and Scripting

Problem in reading file (bash)

i get a name from user first name : last name, in this format. Now i am saving this to a file. what i want is, I do not want to save any name if I already have one entry o that same name..what should i do for example user give robert fernandez this will save in file as robert:fernandez. if... (5 Replies)
Discussion started by: Learnerabc
5 Replies

10. Shell Programming and Scripting

Problem reading file in while/read loop

I know I should be able to see a way of doing this easily, but my brain just won't engage. I have a script working on an embedded device that checks to see if an item is in a blacklist before performing some actions. At the moment the code reads thus.... while read BLACKLIST ; do ... (7 Replies)
Discussion started by: Bashingaway
7 Replies
FGETS(3)								 1								  FGETS(3)

fgets - Gets line from file pointer

SYNOPSIS
string fgets (resource $handle, [int $length]) DESCRIPTION
Gets a line from file pointer. PARAMETERS
o $handle -The file pointer must be valid, and must point to a file successfully opened by fopen(3) or fsockopen(3) (and not yet closed by fclose(3)). o $length - Reading ends when $length - 1 bytes have been read, or a newline (which is included in the return value), or an EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line. Note Until PHP 4.3.0, omitting it would assume 1024 as the line length. If the majority of the lines in the file are all larger than 8KB, it is more resource efficient for your script to specify the maximum line length. RETURN VALUES
Returns a string of up to $length - 1 bytes read from the file pointed to by $handle. If there is no more data to read in the file pointer, then FALSE is returned. If an error occurs, FALSE is returned. CHANGELOG
+--------+-----------------------------+ |Version | | | | | | | Description | | | | +--------+-----------------------------+ | 4.3.0 | | | | | | | fgets(3) is now binary safe | | | | +--------+-----------------------------+ EXAMPLES
Example #1 Reading a file line by line <?php $handle = @fopen("/tmp/inputfile.txt", "r"); if ($handle) { while (($buffer = fgets($handle, 4096)) !== false) { echo $buffer; } if (!feof($handle)) { echo "Error: unexpected fgets() fail "; } fclose($handle); } ?> NOTES
Note If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem. Note People used to the 'C' semantics of fgets(3) should note the difference in how EOF is returned. SEE ALSO
fgetss(3), fread(3), fgetc(3), stream_get_line(3), fopen(3), popen(3), fsockopen(3), stream_set_timeout(3). PHP Documentation Group FGETS(3)
All times are GMT -4. The time now is 03:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy