Suppose I have a list of strings in a file called stringlist...
string1
string2
...
stringn
Suppose also that I have another file, or stdin, or whatever, and I want to use awk to see if some field in each record matches any string in stringlist. What I've been doing is using each string on the list as an index of an array isOnList, and the value of the array element is a unique string, like YUPPERS. This is in my BEGIN block:
Suppose I'm interested in finding out whether, say, field 7 matches anything on the list. I have the list read into the array, so to do the testing in the body of my script, I simply do something like this:
It works, and it seems reasonably efficient, but I wonder if there's a faster, less expensive way to do this. Looping through the array on each line can be pretty costly, I imagine. How would you all go about solving this sort of problem? Thanks.
I need to list the files that do not match the search pattern:
Example:
cat file1
This is how it should work
cat file2
This is why I like Unix
grep -option? Unix * (or some other command)
returns file1 (7 Replies)
Hi ALL,
I am making a script that search all then worldwriteable dir in documentroot.I have manage to find all the dir now i want to match each file extension in worldwriteable against a list of array which contain file like php html etc,if i find any file then print dirname. Dont see to get any... (8 Replies)
Hi,
From the pattern mentioned below remove lines based on pattern range.
Conditions
1 Look For all lines starting with ALTER TABLE and Ending with ; and contains the word MOVE.I wanto to remove these lines from the file sample below.
Note : The above pattern list could be found in... (1 Reply)
Hello,
I'm taking a username from keyboard as input and i want to check if it exists in a list under a directory for example "/home/students/" ....
if there is a match i want to type the list...
can anyone give me an example or a tutorial to read plz?
thnx for your help. (1 Reply)
Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file.
For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt
I tried with grep -A but it's not supported on my system.
I tried with awk,... (4 Replies)
I have a sorted list (python) and I want to insert a string if it matches the pattern in list.
Example :
Sorted List
Above list is in sorted order. I need to insert a name in sorted order and also if the name already exist then it should be inserted before the existing... (1 Reply)
I am trying to look for $2 of file1 (skipping the header) in $2 of file2 (skipping the header) and if they match and the value in $10 is > 30 and $11 is > 49, then print the line from file1 to a output file. If no match is foung the line is not printed. Both the input and output are tab-delimited.... (3 Replies)
I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output.
$1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Full title: How to write a script to match a searched name to a given list, and then returns other names with the same properties
Anyway, first time here, hi! So I'm taking an introductory course at uni and there's a question in our lab that asks us to write a script where a user can search a... (4 Replies)
Discussion started by: aheyhey
4 Replies
LEARN ABOUT MOJAVE
sl_add
STRINGLIST(3) BSD Library Functions Manual STRINGLIST(3)NAME
stringlist, sl_init, sl_add, sl_free, sl_find -- stringlist manipulation functions
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stringlist.h>
StringList *
sl_init();
int
sl_add(StringList *sl, char *item);
void
sl_free(StringList *sl, int freeall);
char *
sl_find(StringList *sl, char *item);
DESCRIPTION
The stringlist functions manipulate stringlists, which are lists of strings that extend automatically if necessary.
The StringList structure has the following definition:
typedef struct _stringlist {
char **sl_str;
size_t sl_max;
size_t sl_cur;
} StringList;
sl_str a pointer to the base of the array containing the list.
sl_max the size of sl_str.
sl_cur the offset in sl_str of the current element.
The following stringlist manipulation functions are available:
sl_init() Create a stringlist. Returns a pointer to a StringList, or NULL in case of failure.
sl_free() Releases memory occupied by sl and the sl->sl_str array. If freeall is non-zero, then each of the items within sl->sl_str is
released as well.
sl_add() Add item to sl->sl_str at sl->sl_cur, extending the size of sl->sl_str. Returns zero upon success, -1 upon failure.
sl_find() Find item in sl, returning NULL if it is not found.
SEE ALSO free(3), malloc(3)HISTORY
The stringlist functions appeared in FreeBSD 2.2.6 and NetBSD 1.3.
BSD November 28, 1999 BSD