Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

strsep(3) [redhat man page]

STRSEP(3)						     Linux Programmer's Manual							 STRSEP(3)

NAME
strsep - extract token from string SYNOPSIS
#include <string.h> char *strsep(char **stringp, const char *delim); DESCRIPTION
If *stringp is NULL, the strsep() function returns NULL and does nothing else. Otherwise, this function finds the first token in the string *stringp, where tokens are delimited by symbols in the string delim. This token is terminated with a `' character (by overwriting the delimiter) and *stringp is updated to point past the token. In case no delimiter was found, the token is taken to be the entire string *stringp, and *stringp is made NULL. RETURN VALUE
The strsep() function returns a pointer to the token, that is, it returns the original value of *stringp. NOTES
The strsep() function was introduced as a replacement for strtok(), since the latter cannot handle empty fields. However, strtok() con- forms to ANSI-C and hence is more portable. BUGS
This function suffers from the same problems as strtok(). In particular, it modifies the original string. Avoid it. CONFORMING TO
BSD 4.4 SEE ALSO
index(3), memchr(3), rindex(3), strchr(3), strpbrk(3), strspn(3), strstr(3), strtok(3) GNU
1993-04-12 STRSEP(3)

Check Out this Related Man Page

STRSEP(3)						     Linux Programmer's Manual							 STRSEP(3)

NAME
strsep - extract token from string SYNOPSIS
#include <string.h> char *strsep(char **stringp, const char *delim); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): strsep(): Since glibc 2.19: _DEFAULT_SOURCE Glibc 2.19 and earlier: _BSD_SOURCE DESCRIPTION
If *stringp is NULL, the strsep() function returns NULL and does nothing else. Otherwise, this function finds the first token in the string *stringp, that is delimited by one of the bytes in the string delim. This token is terminated by overwriting the delimiter with a null byte (''), and *stringp is updated to point past the token. In case no delimiter was found, the token is taken to be the entire string *stringp, and *stringp is made NULL. RETURN VALUE
The strsep() function returns a pointer to the token, that is, it returns the original value of *stringp. ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). +----------+---------------+---------+ |Interface | Attribute | Value | +----------+---------------+---------+ |strsep() | Thread safety | MT-Safe | +----------+---------------+---------+ CONFORMING TO
4.4BSD. NOTES
The strsep() function was introduced as a replacement for strtok(3), since the latter cannot handle empty fields. However, strtok(3) con- forms to C89/C99 and hence is more portable. BUGS
Be cautious when using this function. If you do use it, note that: * This function modifies its first argument. * This function cannot be used on constant strings. * The identity of the delimiting character is lost. SEE ALSO
index(3), memchr(3), rindex(3), strchr(3), string(3), strpbrk(3), strspn(3), strstr(3), strtok(3) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. GNU
2016-03-15 STRSEP(3)
Man Page

9 More Discussions You Might Find Interesting

1. Programming

better way than strtok?

Hi all, Right now I'm using this but it seems to be a hack: if (prefix(arg, "mark=")) { for (markid = strtok(args,"="); markid; markid=strtok((char *)NULL, "=")) { basically the user passes "mark=ny" to the command. I want to be able to extract "ny" from that... (7 Replies)
Discussion started by: annie
7 Replies

2. Solaris

help regarding sed

this is one of the lines in the file.. I need to extract the last token of the lines starting with EVENT and having "NICE alarms" And then put the last token in a new file. for example since the below lines starts with EVENTS and contains "NICE ALARM", i need to extract the last token "normal"... (5 Replies)
Discussion started by: vikashtulsiyan
5 Replies

3. Shell Programming and Scripting

strtok equivalent in perl

Hi All, Is their any equivalent for strtok (in c) to use in perl script. Thanks in advance. JS (1 Reply)
Discussion started by: jisha
1 Replies

4. Shell Programming and Scripting

Parsing string using specific delimiter

Hi, I'm wondering what is the best way to parse out a long string that has a specific deliminator and outputting each token between the delim on a newline? i.e. input text1,text2,text3,tex4 i.e. output text1 text2 text3 text4 (8 Replies)
Discussion started by: primp
8 Replies

5. Shell Programming and Scripting

Extraction of string from Stringlist using delimiter

Hi Experts, I need to extract some set of strings one be one using delimiter. Example: shellscript.sh|unix.sh|script_file.sh i need to extract this shellscript.sh,unix.sh,script_file.sh separately. I tried but couldn't get. Please help me.. Thanks & Regards :), Kanda (3 Replies)
Discussion started by: spkandy
3 Replies

6. UNIX for Dummies Questions & Answers

Getting Substring

Hi, I hav a string lets say aa.txt:bb:txt length of the string can vary.. I have to keep the token inside a array and the delimiter is : plz send me the code (2 Replies)
Discussion started by: Deekay.p
2 Replies

7. Shell Programming and Scripting

Conditional replacement of a delimiter

Hello, I'm new to this forum but this seems like the place to ask this question. I have a pipe delimited data file with the fields except for the header being encased in double quotes. I found out that some of the fields have an trash pipe within the data itself. I'd like to conditionally... (4 Replies)
Discussion started by: samahs
4 Replies

8. Shell Programming and Scripting

Searching for a token in a file

Hi All, I am new to scripting. I have a requirement where I need to search for token present in array in a file. If the token is found I need to take the first column of that line from the file and append it to token and direct it to a new file. e.g. token file token.txt contains abc... (2 Replies)
Discussion started by: alok2082
2 Replies

9. Shell Programming and Scripting

Perl substr or similar help

I have a large string containing about 17,500 characters and I would like to obtain the value for token. token only appears in the entire string once and is towards the end of the string at the 17,200 area but that could change. Using perl can someone assist me with obtaining the value which in... (10 Replies)
Discussion started by: azdps
10 Replies