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 * (6 Replies)
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)
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)
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)
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)
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)
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)
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)
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)
Hello,
I am trying to read a text file into linked list, but always got the first and last records wrong.
1) The problem looks related to the initialization of the node temp with malloc(), but could not figure it out. No error/warning at compiling, though.
2) The output file is empty,... (10 Replies)
Discussion started by: yifangt
10 Replies
LEARN ABOUT OPENSOLARIS
fread
fread(3C) Standard C Library Functions fread(3C)NAME
fread - binary input
SYNOPSIS
#include <stdio.h>
size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
DESCRIPTION
The fread() function reads into the array pointed to by ptr up to nitems elements whose size is specified by size in bytes, from the stream
pointed to by stream. For each object, size calls are made to the fgetc(3C) function and the results stored, in the order read, in an array
of unsigned char exactly overlaying the object. The file-position indicator for the stream (if defined) is advanced by the number of bytes
successfully read. If an error occurs, the resulting value of the file-position indicator for the stream is unspecified. If a partial ele-
ment is read, its value is unspecified.
The fread() function may mark the st_atime field of the file associated with stream for update. The st_atime field will be marked for
update by the first successful execution of fgetc(3C), fgets(3C), fgetwc(3C), fgetws(3C), fread(), fscanf(3C), getc(3C), getchar(3C),
gets(3C), or scanf(3C) using stream that returns data not supplied by a prior call to ungetc(3C) or ungetwc(3C).
RETURN VALUES
Upon successful completion, fread() returns the number of elements successfully read, which is less than nitems only if a read error or
end-of-file is encountered. If size or nitems is 0, fread() returns 0 and the contents of the array and the state of the stream remain
unchanged. Otherwise, if a read error occurs, the error indicator for the stream is set and errno is set to indicate the error.
ERRORS
Refer to fgetc(3C).
EXAMPLES
Example 1 Reading from a Stream
The following example reads a single element from the fp stream into the array pointed to by buf.
#include <stdio.h>
...
size_t bytes_read;
char buf[100];
FILE *fp;
...
bytes_read = fread(buf, sizeof(buf), 1, fp);
...
USAGE
The ferror() or feof() functions must be used to distinguish between an error condition and end-of-file condition. See ferror(3C).
Because of possible differences in element length and byte ordering, files written using fwrite(3C) are application-dependent, and possibly
cannot be read using fread() by a different application or by the same application on a different processor.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
|MT-Level |MT-Safe |
+-----------------------------+-----------------------------+
SEE ALSO read(2), fclose(3C), ferror(3C), fopen(3C), getc(3C), gets(3C), printf(3C), putc(3C), puts(3C), attributes(5), standards(5)SunOS 5.11 24 Jul 2002 fread(3C)