03-25-2010
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have an inputfile that I trying to awk with a getline(Solaris v8 ksh). However I need to have the results be a unique. Is there a comparable command within awk to return a unique result? Or can you break out of the awk to add a uniq. I am looking for something more complex then a pipe... (6 Replies)
Discussion started by: gozer13
6 Replies
2. UNIX for Dummies Questions & Answers
hi , I got a script that I don't understand.
awk '{
command="echo "$1
command | getline echome
close(command)
print $0 "\t" echome
}' < user.list
It reads the file user.list
user.list
London John
Bridge Peter
and sends the stream to the awk command.
I don't understand what is... (3 Replies)
Discussion started by: remid1985
3 Replies
3. Shell Programming and Scripting
hello collegues,
I am attempting to use awk to search file1 (serverlist.csv) from each row with file2 (supported.txt). If the is no entry exists in serverlist then output to a file called notsupp.out if there is an entry output to supp.out
I can do this with basic shell scripting however... (0 Replies)
Discussion started by: chlawren
0 Replies
4. Shell Programming and Scripting
How do you make the getline function return to the original line?
The example below should make it clear where I am currently going wrong.
Thanks
AWK SCRIPT:
-------------
awk -F '-' '{
tmpLine = "EMPTY"
print "CURRENT LINE :"$0
getline tmpLine
print "NEXT LINE :"tmpLine
}'... (1 Reply)
Discussion started by: garethsays
1 Replies
5. Shell Programming and Scripting
I am using awk and want to use getline from a file like below
getline x < file
However file consists of two columns and I only want to store $2
Any way I can do this?
---------- Post updated at 06:54 AM ---------- Previous update was at 06:45 AM ----------
Done something like this.... (1 Reply)
Discussion started by: kristinu
1 Replies
6. Programming
I can not get 'getline()' to compile. I have tried.
string curLine; //= compiler error
char* curLine; //=compiler error
char curLine; //=compiler error
Every example I see uses a string as a getline(); parameter. It does not work for me on Fedora14 with gcc-c++. Thank you so much. This... (1 Reply)
Discussion started by: sepoto
1 Replies
7. Shell Programming and Scripting
I'm running the script below and get the output below against a file with
lineA=aaa
lineB=bbb
lineC=ccc
lineD=ddd
I get output:
lineC=ccc
lineD=ddd
I need the output to be:
lineB=bbb
lineC=ccc
lineD=ddd
cat filename | nawk '/lineA=aaa/ {
getline;
do {
getline (3 Replies)
Discussion started by: toor13
3 Replies
8. Shell Programming and Scripting
Here is I want to do:
find lines in file filteredtrace.txt which is not continued as
a multiply of 4 and strip them from file original_trace_framno.
problem is awk used the ' symbol
so pipe of getline has to use the " symbol
while agument of sed has to use the " symbol,
it doesn't... (8 Replies)
Discussion started by: lzq420241
8 Replies
9. Programming
Hi All,
When I do man getline on my Linux system (in BASH), I see an example C code where a file is being read using getline() function.
Now, my question is why there is no fclose() to close the open file pointer?
People who don't have a Linux system, this is the code that I am referring... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies
10. Shell Programming and Scripting
Hi,
I have an awk script with the following function in it .
function cmd( c )
{
while( ( c | getline foo) > 0 ){
return foo ;
close( c );
}
}
c =... (4 Replies)
Discussion started by: MetaMan
4 Replies
LEARN ABOUT DEBIAN
getline
GETLINE(3) Linux Programmer's Manual GETLINE(3)
NAME
getline, getdelim - delimited string input
SYNOPSIS
#include <stdio.h>
ssize_t getline(char **lineptr, size_t *n, FILE *stream);
ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
getline(), getdelim():
Since glibc 2.10:
_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700
Before glibc 2.10:
_GNU_SOURCE
DESCRIPTION
getline() reads an entire line from stream, storing the address of the buffer containing the text into *lineptr. The buffer is null-termi-
nated and includes the newline character, if one was found.
If *lineptr is NULL, then getline() will allocate a buffer for storing the line, which should be freed by the user program. (In this case,
the value in *n is ignored.)
Alternatively, before calling getline(), *lineptr can contain a pointer to a malloc(3)-allocated buffer *n bytes in size. If the buffer is
not large enough to hold the line, getline() resizes it with realloc(3), updating *lineptr and *n as necessary.
In either case, on a successful call, *lineptr and *n will be updated to reflect the buffer address and allocated size respectively.
getdelim() works like getline(), except that a line delimiter other than newline can be specified as the delimiter argument. As with get-
line(), a delimiter character is not added if one was not present in the input before end of file was reached.
RETURN VALUE
On success, getline() and getdelim() return the number of characters read, including the delimiter character, but not including the termi-
nating null byte. This value can be used to handle embedded null bytes in the line read.
Both functions return -1 on failure to read a line (including end-of-file condition).
ERRORS
EINVAL Bad arguments (n or lineptr is NULL, or stream is not valid).
VERSIONS
These functions are available since libc 4.6.27.
CONFORMING TO
Both getline() and getdelim() were originally GNU extensions. They were standardized in POSIX.1-2008.
EXAMPLE
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
FILE *fp;
char *line = NULL;
size_t len = 0;
ssize_t read;
fp = fopen("/etc/motd", "r");
if (fp == NULL)
exit(EXIT_FAILURE);
while ((read = getline(&line, &len, fp)) != -1) {
printf("Retrieved line of length %zu :
", read);
printf("%s", line);
}
free(line);
exit(EXIT_SUCCESS);
}
SEE ALSO
read(2), fgets(3), fopen(3), fread(3), gets(3), scanf(3)
COLOPHON
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU
2010-06-12 GETLINE(3)