C does not change what variables do depending on their type, or do anything for you when you ask it to convert one type to another. At best, it will ball it up and cram it through the mail slot, i.e. take you completely literally rather than doing the extra work you wanted.
So, if you want the string to be split, you're going to have to tell it to split it.
strtok is fairly good at doing that. It breaks strings apart on a list of letters, any letter in the list is considered a separator. (I add \n to remove newlines from the end while its at it.)
Two caveats:
It modifies buf. For example, the line a:b:c:d:e\n would become a\0b\0c\0d\0e\0. So you can't call it on anything you can't modify, i.e. strtok("a:b:c:d:e", ":"); would crash.
It returns pointers to things inside buf. Every time you overwrite buf[], i.e. every time you call fgets(), all the pointers strtok() gave you last time will point anywhere or nowhere.
Last edited by Corona688; 12-19-2014 at 05:48 PM..
These 2 Users Gave Thanks to Corona688 For This Post:
I try to get the month (of last save) and the filename into a variable, is this possible ?
something like this :
for month in `ls -la | awk '{print $6}'`
do
if ]
then
a=filename of the matching file
cp $a /Sep
fi
thanks,
Steffen (1 Reply)
Hi,
Hi, I run the command:
hostname to get the host back from the server: db201
Now, I need to take that result and set it to a variable. Can anyone help me with this?? I need to be able to use the same script on multiple servers so I do not want to hardcode the hostname result into... (1 Reply)
Hi
Can anybody tell me how can I dump the results of execution of a command into array form? For example, I want to execute:
and put each part of the result in an array element:
Thanks (2 Replies)
Hi,
In a kshell , i need to compare the results of two array .
each Non-match value should copy to a new array.
For example:
==========
Array one contain the following values:
A
B
C
Array two contain the following values:
C
F
A
E
After comparing this arrays , a new array should... (4 Replies)
How can I send the results of a query to a unix variable. I basically want to run a query then do some logic on the results. Trying to redirect the result into a variable I define in the script.
select count(*) as counter from table - nut to redirect the "count" returned from the query... (2 Replies)
I'm trying to add the paths of all the xml files in certain directories to an array. I want to use the array later in my code. Anyway, for some reason this isn't working. Any help would be appreciated.
Path_Counter=0
for result in "find * -name '*.xml'"; do
XmlPath="$result"
echo... (2 Replies)
Here is one I am baffled with; I have not used unix for a while and now that I am back it has been fun remembering and I have enjoyed it, for the most past. this is in ksh.
I need to search in a file for the line with X1 and cut columns 20-25, put them into a variable, added them (dollar... (3 Replies)
Requirement 1) I need to execute 15 SQL queries in oracle through linux script. All these query results needs to be stored in array variables.
Requirement 2) And these 15 queries needs to be executed in parallel.
Requirement 3) Once all the queries executed then the shell script should... (3 Replies)
for a in {1..100}
do
awk '{ sum+=$a} END {print sum}' a=$a file1 > file2
done
I know I will get only one number if following the code above, how can I get 100 sum numbers in file2? (2 Replies)
Good morning all,
This is the file name in question OD_Orders_2019-02-19.csv
I am trying to create a bash script to read into files with yesterdays date on the file name while retaining the rest of the files name. I would like for $y to equal, the name of the file with a formula output with... (2 Replies)
Discussion started by: Ibrahim A
2 Replies
LEARN ABOUT MOJAVE
wcstok
WCSTOK(3) BSD Library Functions Manual WCSTOK(3)NAME
wcstok -- split wide-character string into tokens
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <wchar.h>
wchar_t *
wcstok(wchar_t *restrict ws1, const wchar_t *restrict ws2, wchar_t **restrict ptr);
DESCRIPTION
The wcstok() function is used to isolate sequential tokens in a null-terminated wide character string, ws1. These tokens are separated in
the string by at least one of the characters in ws2. The first time that wcstok() is called, ws1 should be specified; subsequent calls,
wishing to obtain further tokens from the same string, should pass a null pointer instead. The separator string, ws2, must be supplied each
time, and may change between calls. The context pointer, ptr, must be provided on each call.
The wcstok() function is the wide character counterpart of the strtok_r() function.
RETURN VALUES
The wcstok() function returns a pointer to the beginning of each subsequent token in the string, after replacing the token itself with a null
wide character (L'