07-23-2010
Thank You. It works. Is there any way to do it without mentioning the field names in the code ?
It should read file provided the fields are in said format i.e. <field name> : <field value>
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Is anyone able to help with writing a program that will do the following:
1. Read the contents of a file, line by line, and on each line, assign each of the two columns to a shell variable.
2. perform an action on the variables
3. Read the next line.
Here is what I've gotten so far. ... (3 Replies)
Discussion started by: akbar
3 Replies
2. Shell Programming and Scripting
Hello,
I have a cat.dat file, i would like shell to read each 3 lines and set this 3 lines to 3 different variables.
my cat.dat is:
11
12
+380486461001
12
13
+380486461002
13
14
+380486461003
i want shell to make a loop and assign 1st line to student_id, 2nd line to... (4 Replies)
Discussion started by: rosalinda
4 Replies
3. Shell Programming and Scripting
Hi,
I have a file like the following...
CUST=
DIR=
NULIST=
name=philps_123
How can i add values to each of these unassigned variables using a shell script?
say for eg: i have values for CUST as onida, dir as /dir/onida, NULIST as /tmp/onida_files. How can i add these values to... (11 Replies)
Discussion started by: Tuxidow
11 Replies
4. Shell Programming and Scripting
File having data in following format :
file name : file.txt
--------------------
111111;name1
222222;name2
333333;name3
I want to read this file so that I can split these into two paramaters i.e. 111111 & name1 into two different variables(say value1 & value2).
i.e val1=11111 &... (2 Replies)
Discussion started by: sjoshi98
2 Replies
5. Shell Programming and Scripting
How can I read a string delimited on spaces and assign the fields to incremented variables.
For example:
Given $exts= txt dat mov
I want to read in $exts and have "txt" "dat" and "mov" assigned to incremented variables like $ext1, $ext2, etc. I would like to do this in a loop so that I can... (4 Replies)
Discussion started by: runit
4 Replies
6. Shell Programming and Scripting
Hi,
I have requirement to assign values to variables which are created dynamically.
Below is the code which i am using to achieve above requirement.
#!/bin/ksh
oIFS="$IFS"; IFS=','
STR_FAIL_PARENT_IF_FAILS="WF_F_P_IF_FAILS1,WF_F_P_IF_FAILS2,WF_F_P_IF_FAILS3"
set -A... (1 Reply)
Discussion started by: tmalik79
1 Replies
7. Shell Programming and Scripting
For eg: I have sample.txt file with 4 rows of record like:
user1|password1
user2|password2
user3|password3
user4|password4
The username and password is sepsrated by '|'
I want to get the 1st row value from the file and assign it to two different variables(username and password)
in my... (1 Reply)
Discussion started by: priya001
1 Replies
8. Shell Programming and Scripting
I am trying to read a input file which has two columns separated by space
Input file
server1 server2
server3 server4
server5 server6
When i execute the below while code it reads line by line and a and b variables are able to successfully fetch the values
while read a b
do
echo "$a"
echo... (5 Replies)
Discussion started by: chidori
5 Replies
9. Shell Programming and Scripting
I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables.
I need to read this file which is an input to my script
Config.txt
file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies
10. Shell Programming and Scripting
I've got a file that looks like this (spaces before first entries intentional):
12345650-000005000GL140227 ANNUAL HELC FEE EN
22345650-000005000GL140227 ANNUAL HELC FEE EN
32345650-000005000GL140227 ANNUAL HELC FEE EN
I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies
LEARN ABOUT CENTOS
sd_journal_query_unique
SD_JOURNAL_QUERY_UNIQUE(3) sd_journal_query_unique SD_JOURNAL_QUERY_UNIQUE(3)
NAME
sd_journal_query_unique, sd_journal_enumerate_unique, sd_journal_restart_unique, SD_JOURNAL_FOREACH_UNIQUE - Read unique data fields from
the journal
SYNOPSIS
#include <systemd/sd-journal.h>
int sd_journal_query_unique(sd_journal* j, const char* field);
int sd_journal_enumerate_unique(sd_journal* j, const void** data, size_t* length);
void sd_journal_restart_unique(sd_journal* j);
SD_JOURNAL_FOREACH_UNIQUE(sd_journal* j, const void* data, size_t length);
DESCRIPTION
sd_journal_query_unique() queries the journal for all unique values the specified field can take. It takes two arguments: the journal to
query and the field name to look for. Well-known field names are listed on systemd.journal-fields(7). Field names must be specified without
a trailing '='. After this function has been executed successfully the field values may be queried using sd_journal_enumerate_unique().
Invoking this call a second time will change the field name being queried and reset the enumeration index to the first field value that
matches.
sd_journal_enumerate_unique() may be used to iterate through all data fields which match the previously selected field name as set with
sd_journal_query_unique(). On each invocation the next field data matching the field name is returned. The order of the returned data
fields is not defined. It takes three arguments: the journal context object, plus a pair of pointers to pointer/size variables where the
data object and its size shall be stored in. The returned data is in a read-only memory map and is only valid until the next invocation of
sd_journal_enumerate_unique(). Note that the data returned will be prefixed with the field name and '='. Note that this call is subject to
the data field size threshold as controlled by sd_journal_set_data_threshold().
sd_journal_restart_unique() resets the data enumeration index to the beginning of the list. The next invocation of
sd_journal_enumerate_unique() will return the first field data matching the field name again.
Note that the SD_JOURNAL_FOREACH_UNIQUE() macro may be used as a handy wrapper around sd_journal_restart_unique() and
sd_journal_enumerate_unique().
Note that these functions currently are not influenced by matches set with sd_journal_add_match() but this might change in a later version
of this software.
RETURN VALUE
sd_journal_query_unique() returns 0 on success or a negative errno-style error code. sd_journal_enumerate_unique() returns a positive
integer if the next field data has been read, 0 when no more fields are known, or a negative errno-style error code.
sd_journal_restart_unique() returns nothing.
NOTES
The sd_journal_query_unique(), sd_journal_enumerate_unique() and sd_journal_restart_unique() interfaces are available as a shared library,
which can be compiled and linked to with the libsystemd-journal pkg-config(1) file.
EXAMPLES
Use the SD_JOURNAL_FOREACH_UNIQUE macro to iterate through all values a field of the journal can take. The following example lists all unit
names referenced in the journal:
#include <stdio.h>
#include <string.h>
#include <systemd/sd-journal.h>
int main(int argc, char *argv[]) {
sd_journal *j;
const void *d;
size_t l;
int r;
r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
if (r < 0) {
fprintf(stderr, "Failed to open journal: %s
", strerror(-r));
return 1;
}
r = sd_journal_query_unique(j, "_SYSTEMD_UNIT");
if (r < 0) {
fprintf(stderr, "Failed to query journal: %s
", strerror(-r));
return 1;
}
SD_JOURNAL_FOREACH_UNIQUE(j, d, l)
printf("%.*s
", (int) l, (const char*) d);
sd_journal_close(j);
return 0;
}
SEE ALSO
systemd(1), systemd.journal-fields(7), sd-journal(3), sd_journal_open(3), sd_journal_get_data(3), sd_journal_add_match(3)
systemd 208 SD_JOURNAL_QUERY_UNIQUE(3)