Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

read(2) [v7 man page]

READ(2) 							System Calls Manual							   READ(2)

NAME
read - read from file SYNOPSIS
read(fildes, buffer, nbytes) char *buffer; DESCRIPTION
A file descriptor is a word returned from a successful open, creat, dup, or pipe call. Buffer is the location of nbytes contiguous bytes into which the input will be placed. It is not guaranteed that all nbytes bytes will be read; for example if the file refers to a type- writer at most one line will be returned. In any event the number of characters read is returned. If the returned value is 0, then end-of-file has been reached. SEE ALSO
open(2), creat(2), dup(2), pipe(2) DIAGNOSTICS
As mentioned, 0 is returned when the end of the file has been reached. If the read was otherwise unsuccessful the return value is -1. Many conditions can generate an error: physical I/O errors, bad buffer address, preposterous nbytes, file descriptor not that of an input file. ASSEMBLER
(read = 3.) (file descriptor in r0) sys read; buffer; nbytes (byte count in r0) READ(2)

Check Out this Related Man Page

READ(2) 							System Calls Manual							   READ(2)

NAME
read - read input SYNOPSIS
#include <sys/types.h> #include <unistd.h> ssize_t read(int d, void *buf, size_t nbytes) DESCRIPTION
Read attempts to read nbytes of data from the object referenced by the descriptor d into the buffer pointed to by buf. On objects capable of seeking, the read starts at a position given by the pointer associated with d (see lseek(2)). Upon return from read, the pointer is incremented by the number of bytes actually read. Objects that are not capable of seeking always read from the current position. The value of the pointer associated with such an object is undefined. Upon successful completion, read return the number of bytes actually read and placed in the buffer. The system guarantees to read the num- ber of bytes requested if the descriptor references a normal file that has that many bytes left before the end-of-file, but in no other case. If the returned value is 0, then end-of-file has been reached. RETURN VALUE
If successful, the number of bytes actually read is returned. Otherwise, a -1 is returned and the global variable errno is set to indicate the error. ERRORS
Read will fail if one or more of the following are true: [EBADF] D is not a valid descriptor open for reading. [EFAULT] Buf points outside the allocated address space. [EIO] An I/O error occurred while reading from the file system. [EINTR] A read from a slow device was interrupted before any data arrived by the delivery of a signal. [EAGAIN] The file was marked for non-blocking I/O, and no data were ready to be read. SEE ALSO
dup(2), fcntl(2), open(2), pipe(2), write(2). 4th Berkeley Distribution May 23, 1986 READ(2)
Man Page

11 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I add 4 lines together and then read the next 4 lines?

Hi, I have grep:ed on a file with which gives the below output. Total = 43 Total = 21 Total = 23 Total = 2 Total = 3 Total = 1 Total = 0 I would like to add the first 4th lines to a total amount, and do so on for the rest of the lines. I was thinking in terms of using while read.... (32 Replies)
Discussion started by: mr_andrew
32 Replies

2. Shell Programming and Scripting

How to read n number of lines from a file

Hiii I am very new to shell scripting.This is my data file a.txt: 56 45.78 1000 11.23 76.89 45 34.56 23 3400 100 .......... Now i am must use shell scripting to read n number of lines from the file & from ts n number of lines i need to find greatest number among them & so on for... (44 Replies)
Discussion started by: varsha
44 Replies

3. Shell Programming and Scripting

Measure thread execution (in C, unix)

Hi, I have a simulation program which creates two threads and I would like to know if I can measure the time of each individual thread. Threads communicate (I use pthread to manage them) and I want to measure communication time. I found a solution with clock_gettime and CLOCK_THREAD_CPUTIME_ID... (32 Replies)
Discussion started by: Tinkh
32 Replies

4. Shell Programming and Scripting

Read a CSV file and generate SQL output

Friends, This is what I need: I will pass a CSV file as an input, and I want my shell to be reading that CSV file, and based on the parameters it should generate SQLs and write those SQL in a different file in the same location. I'm new to Shell scripting. I'm currently working on a... (25 Replies)
Discussion started by: Ram.Math
25 Replies

5. Shell Programming and Scripting

how to run an already made script run against a list of ip addresses solaris 8 question

how to run an already developed script run against a list of ip addresses solaris 8 question. the script goes away and check traffic information, for example check_GE-VLANStats-P3 1.1.1.1 and returns the results ok. how do I run this against an ip list? i.e a list of 30 ip addresses (26 Replies)
Discussion started by: llcooljatt
26 Replies

6. Shell Programming and Scripting

How to read values and store in array?

I am reading a value from a file and want to store the value in a dynamic array as i don't know the number of occurrences of the value in that file. How can i do that and then later fetch that value from array (25 Replies)
Discussion started by: Prachi Gupta
25 Replies

7. Shell Programming and Scripting

How to read and Split a file?

Hi, I have a .csv file which I want to split into smaller files as .csv format only Thanks in advance. (26 Replies)
Discussion started by: azherkn3
26 Replies

8. Shell Programming and Scripting

Read multiple text files and copy data to csv

hi i need to extract lines from multiple files to a csv file. for example, i have these 3 files file1.txt date:29dec1980 caller:91245824255 called:8127766 file2.txt date:11apr2014 caller:9155584558 called:8115478 file3.txt date:25jun2015 caller:445225552 called:8117485 (30 Replies)
Discussion started by: lp.descamps
30 Replies

9. Shell Programming and Scripting

UNIX Shell Scripting (Solaris) for File Checking

Hi guys, I'm sorry but i badly need your help. I am assigned to do a basic shell script in my job but sadly i don't have any idea on what it is because i am an electronics engineer, but i googled all of it, ask my friends but i cant finalize my scripts. so do please help me. The requirement... (47 Replies)
Discussion started by: daveaztig14
47 Replies

10. What is on Your Mind?

Forum Display - Thread Preview Text Animation

Instead of the slow and not readable tooltips with the preview of the thread content in forum view, I have added the preview with mouseover (see attached movie). Let me know if you want a different kind of preview (animation, duration font-color, size, etc,) Thanks. <script>... (29 Replies)
Discussion started by: Neo
29 Replies

11. What is on Your Mind?

New Icons Coming from Font Awesome

Finally making some progress on getting rid of the 10 year old buttons with modern day fonts and icons thanks to a responsive web design tutorial by Brad Traversy who's video pointed me to Font Awesome. The buttons and icons were pretty easy to implement but it too me a number of hours... (39 Replies)
Discussion started by: Neo
39 Replies