10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello,
I would need to replace a delimiter in a flat file using.I would like to replace the semicolon (";") but only if it was contained in a string between quotes. For example:
Original flat file example:
abc;abc;"abc;abc";cd;"ef;ef";abc
aa;bb;"aa";cc;"ddd;eee";ff
Desired output:... (9 Replies)
Discussion started by: bartleby
9 Replies
2. Shell Programming and Scripting
Hi All,
I'm stuck-up in finding a way to skip the delimiter which come within double quotes using awk or any other better option. can someone please help me out.
Below are the details:
Delimited: |
Sample data: 742433154|"SYN|THESIS MED CHEM PTY.... (2 Replies)
Discussion started by: BrahmaNaiduA
2 Replies
3. Shell Programming and Scripting
Hi All,
i have file name like below
ABC_065224_123456_123456_your_130413_163005.txt
ABC_065224_123456_MAIN_20130413_163005.txt
ABC_065224_123456_123456_MAIN_130413_163005.txt
ABC_065224_123456_123456_434567_MAIN_130413_163005.txt
i need to find out the number of characters in the filed... (6 Replies)
Discussion started by: dssyadav
6 Replies
4. Shell Programming and Scripting
Basically , i want to delete strings of a particular pattern from the flat file which is " | " pipe delimited.
Below are the valid formats :
1) AAA (0) 111-111-111, AAA, BB
2) AAA (0) 111-111-1111;X, AAA, BB
original flat file example :
|ABC ABC XHAMK|AAA (0) 111-111-111, AAA,... (3 Replies)
Discussion started by: Ravi_007
3 Replies
5. Shell Programming and Scripting
Good afternoon!
I have an XML file from which I want to extract only certain elements contained within each line. The problem is that the format of each line is not exactly the same (though similiar). For example, oa_var will be in each line, however, there may be no value or other... (3 Replies)
Discussion started by: bab@faa
3 Replies
6. Shell Programming and Scripting
I have a line of text for example
aaaa bbbb cccc dddd eeee ffffff
I would need to get the cccc however bbbb could be there or not.
So whether bbbb is in the line or not I need cccc.
I was looking at either awk or sed....and trying to start at c and end until the next space.
Also... (11 Replies)
Discussion started by: bombcan1
11 Replies
7. Shell Programming and Scripting
I need to extract certain pieces from a string, wher delimiters may vary. For example
A0 B0 C0 12345677 X0 Y0 Z0
A1-B1 C1 12345678 X1 Y0 Z0
A1/B2 C77 12345679 X2 Y0 Z0
I need to get
C0 12345677 X0
C1 12345678 X1
C77 12345679 X2
I tried sed, see example below:
echo 'A0 B0... (2 Replies)
Discussion started by: migurus
2 Replies
8. Shell Programming and Scripting
Hi,
Please help me to extrat values b/w two delimiters.
$ echo $abc
i want to extract the value 12345 b/w %. (5 Replies)
Discussion started by: tsaravanan
5 Replies
9. UNIX for Advanced & Expert Users
I have an input file which looks like
"
@$SCRIPT/atp_asrmt_adj.sql
$SCRIPT/dba2000.scr -s / @$SCRIPT/cim1005w.pls
$SCRIPT/dba2000.scr -s / @$SCRIPT/cim1006w.pls
start $SCRIPT/cim1020d.sql;^M
spool $DATA/cim1021m.sql
@$DATA/cim1021m.sql
! rm $DATA/cim1021m.sql
spool $DATA/cim1021m.sql... (6 Replies)
Discussion started by: dowsed4u8
6 Replies
10. Solaris
My input file looks like
"
@$SCRIPT/atp_asrmt_adj.sql
$SCRIPT/dba2000.scr -s / @$SCRIPT/cim1005w.pls
$SCRIPT/dba2000.scr -s / @$SCRIPT/cim1006w.pls
start $SCRIPT/cim1020d.sql;^M
spool $DATA/cim1021m.sql
@$DATA/cim1021m.sql
! rm $DATA/cim1021m.sql
spool $DATA/cim1021m.sql... (1 Reply)
Discussion started by: dowsed4u8
1 Replies
strtok(3) Library Functions Manual strtok(3)
NAME
strtok, strtok_r - Split string into tokens
LIBRARY
Standard C Library (libc.so, libc.a)
SYNOPSIS
#include <string.h>
char *strtok(
char *s1,
const char *s2);
char *strtok_r(
char *s1,
const char *s2,
char **savept);
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
strtok_r(): POSIX.1c
strtok(): XPG4, XPG4-UNIX
Refer to the standards(5) reference page for more information about industry standards and associated tags.
PARAMETERS
Contains a pointer to the string to be searched. Contains a pointer to the string of byte token delimiters. [POSIX] Identifies the loca-
tion of the byte where the search for tokens should be started in the next call to strtok_r(). The savept parameter contains a pointer to a
variable that contains a pointer to the byte in the string.
DESCRIPTION
The strtok() function splits the string pointed to by the s1 parameter into a sequence of tokens, each of which is delimited by a byte
equal to one of the bytes in the s2 parameter.
Usually, the strtok() function is called repeatedly to extract the tokens in a string. The first time the application program calls the
strtok() function, it sets the s1 parameter to point to the input string. The function returns a pointer to the first token. Then the
application program calls the function again with the s1 parameter set to the null pointer. This call returns a pointer to the next token
in the string. The application program repeats the call to strtok() with the s1 parameter set to the null pointer until all the tokens in
the string have been returned.
Note
If the input string contains no instances of bytes from the delimiter string, the first call to strtok() results in the return of a pointer
to the original string. On subsequent calls, strtok() returns NULL.
In the initial call to strtok(), the function first searches the string pointed to by the s1 parameter to locate the first byte that does
not occur in the delimiter string pointed to by the s2 parameter. If such a byte is found, it is the start of the first token. The str-
tok() function then searches from there for a byte that does occur in the delimiter string. If such a delimiter is found, strtok() over-
writes it with a null byte, which terminates the current token. The strtok() function saves a pointer to the byte following the null byte
and returns a pointer to the start of the token.
In the subsequent calls to strtok(), in which the s1 parameter is set to the null pointer, the function starts at its saved pointer and
searches for the next byte that does not occur in the delimiter string pointed to by the s2 parameter. If such a byte is found, it is the
start of the new token. The strtok() function then searches from there for a byte that does occur in the delimiter string. If such a
delimiter is found, strtok() overwrites it with a null byte, which terminates the new token. The strtok() function saves a pointer to the
byte following the null byte and returns a pointer to the start of the new token.
If a call to the strtok() function cannot find a byte that does not occur in the delimiter string, it returns the null pointer. If a call
to the strtok() function cannot find the terminating byte that does occur in the delimiter string, the current token extends to the end of
the string and subsequent calls to strtok() will return the null pointer.
If the delimiters used in the string change from one set of characters to another within the string, the application program can set the
second parameter, s2, to different strings from call to call.
The implementation behaves as though no function calls the strtok() function.
The strtok_r() function is the reentrant version of strtok(). Upon successful completion, the strtok_r() function stores the saved pointer
in *savept. If the s1 parameter is a null pointer, the strtok_r() function uses the saved pointer in *savept to start searching for the
next token. In the initial call to strtok_r(), the *savept must be the null pointer.
NOTES
[POSIX] The strtok() function is not supported for multithreaded applications. Instead, its reentrant equivalent, strtok_r(), should be
used with multiple threads.
EXAMPLES
The following example demonstrates how to split a string into tokens.
#include <string.h> #include <locale.h> #include <stdio.h> #define LENGTH 40
main() {
char string1[LENGTH], delimiters[LENGTH];
char *pstr ;
int counter;
(void)setlocale(LC_ALL, "");
printf("Enter the string to be searched: ");
if (fgets(string1, LENGTH, stdin) != NULL) {
printf("Enter the delimiter(s): ");
if (fgets(delimiters, LENGTH, stdin) != NULL) {
if ((pstr = strtok(string1, delimiters ))
!= NULL) {
/* pstr points to the first token */
printf("Token 1 is %s
", pstr);
counter = 2;
while ((pstr = strtok((char *)NULL, delimiters ))
!= NULL) {
printf("Token %d is %s
", counter, pstr);
counter++;
}
}
}
} }
RETURN VALUES
Upon successful completion, the strtok() and strtok_r() functions return a pointer to the first byte of the parsed token in the string.
When there is no token in the string, a null pointer is returned.
RELATED INFORMATION
Functions: string(3), wcstok(3), wcstok_r(3)
Standards: standards(5) delim off
strtok(3)