How to search for string and return binary result?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to search for string and return binary result?
Prev   Next
# 1  
Old 08-05-2010
How to search for string and return binary result?

Hi,

I have a problem that I am sure someone will know the answer to. Currently I have a script which returns a binary output if it finds a certain search string (in this case relating to a DRBD cluster) as follows:
Code:
searchstring="cs:Connected st:Primary/Secondary ds:UpToDate/UpToDate"
[ $(grep -c "$searchstring" /proc/drbd) -gt 0 ] && echo 1 || echo 0

What I need is to make a new script that will search for a string, but rather than searching a file, I want to search the last 10 lines of a file, and return 1 if its found and 0 if not. I guess I'll have to use tail but not sure of the syntax.

Thanks for any help!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

C program to read a binary file and search for a string?

Hi, I am not a C programmer. The only C exposure I have is reading and completing the exercises from the C (ANSI C ) Programming Language book:o At the moment, I am using the UNIX strings command to extract information for a binary file and grepping for a particular string and the value... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

3. Shell Programming and Scripting

bash: need to have egrep to return a text string if the search pattern has NOT been found

Hello all, after spending hours of searching the web I decided to create an account here. This is my first post and I hope one of the experts can help. I need to resolve a grep / sed / xargs / awk problem. My input file is just like this: ----------------------------------... (6 Replies)
Discussion started by: bash4ever
6 Replies

4. Shell Programming and Scripting

Search file for string and store last result to variable

Hi, I'm trying to search a text file for a string: "energy(sigma->0)=". To do so, I executed the grep command, which returned many matches, for example: energy without entropy = -112.16486170 energy(sigma->0) = -112.16520778 energy without entropy = -112.16488936 ... (5 Replies)
Discussion started by: gwr
5 Replies

5. Shell Programming and Scripting

search 32 bit binary for the 1's and return a 1 to the placeholder variable

Folks , I have a korn shell script that i have written for assembly, the variable that is a final result is returning hexadecimal, now the value is to be converted to binary and return the place holder in the binary that has a 1 in its place and send it to a variable assigned for the... (0 Replies)
Discussion started by: venu
0 Replies

6. UNIX for Dummies Questions & Answers

search for string and return substring

Hi, I have a file with the following contents: I need to create a script or search command that will search for this string 'ENDC' in the file. This string is unique and only occurs in one record. Once it finds the string, I would like it to return positions 101-109 ( this is the date of... (0 Replies)
Discussion started by: Lenora2009
0 Replies

7. UNIX for Dummies Questions & Answers

Search for string and return lines above and below

Hi, I have a file with the following contents: COMPANY ABCD TRUCKER JOE SMITH TRUCK 456 PLATE A12345678 TRUCKER BILL JONES TRUCK 789 PLATE B7894561 I need to create a script or search command that will search for this string '789' in the file. This string is unique and only... (7 Replies)
Discussion started by: doza22
7 Replies

8. Shell Programming and Scripting

Search string and return only the 5th line

I have looked at almost every posting on here regarding, grep, sed, awk, nawk, perl methods to perform this function, but they are just not returning the results I hope to see. Example File: abcdef 123456 ghijkl 7890123 7890123 7890123 7890123 mnopqrs 456789 This is the most... (4 Replies)
Discussion started by: doza22
4 Replies

9. UNIX for Dummies Questions & Answers

Any way to grep a string in directories and return the result with diskusage aswell?

What Im basically trying to do is this: I have a small script that can grep any parameter entered into a search string, then print to the screen the name of each file the parameter appears in as well as the file path, ie the directory. The code Im using just for this is.... Directory... (3 Replies)
Discussion started by: Eddeh
3 Replies

10. Shell Programming and Scripting

String search and return value from column

Dear All I had below mention file as my input file. 87980457 Jan 12 2008 2:00AM 1 60 BSC1 81164713 Jan 12 2008 3:00AM 1 60 BSC2 78084521 Jan 12 2008 4:00AM 1 60 BSC3 68385193... (3 Replies)
Discussion started by: jaydeep_sadaria
3 Replies
Login or Register to Ask a Question
TSEARCH(3)						   BSD Library Functions Manual 						TSEARCH(3)

NAME
tsearch, tfind, tdelete, twalk -- manipulate binary search trees SYNOPSIS
#include <search.h> void * tdelete(const void * restrict key, void ** restrict rootp, int (*compar) (const void *, const void *)); void * tfind(const void *key, void * const *rootp, int (*compar) (const void *, const void *)); void * tsearch(const void *key, void **rootp, int (*compar) (const void *, const void *)); void twalk(const void *root, void (*action) (const void *, VISIT, int)); DESCRIPTION
The tdelete(), tfind(), tsearch(), and twalk() functions manage binary search trees based on algorithms T and D from Knuth (6.2.2). The com- parison function passed in by the user has the same style of return values as strcmp(3). The tfind() function searches for the datum matched by the argument key in the binary tree rooted at rootp, returning a pointer to the datum if it is found and NULL if it is not. The tsearch() function is identical to tfind() except that if no match is found, key is inserted into the tree and a pointer to it is returned. If rootp points to a NULL value a new binary search tree is created. The tdelete() function deletes a node from the specified binary search tree and returns a pointer to the parent of the node to be deleted. It takes the same arguments as tfind() and tsearch(). If the node to be deleted is the root of the binary search tree, rootp will be adjusted. The twalk() function walks the binary search tree rooted in root and calls the function action on each node. The action function is called with three arguments: a pointer to the current node, a value from the enum typedef enum { preorder, postorder, endorder, leaf } VISIT; speci- fying the traversal type, and a node level (where level zero is the root of the tree). RETURN VALUES
The tsearch() function returns NULL if allocation of a new node fails (usually due to a lack of free memory). The tfind(), tsearch(), and tdelete() functions return NULL if rootp is NULL or the datum cannot be found. The twalk() function returns no value. SEE ALSO
bsearch(3), hsearch(3), lsearch(3) BSD
June 15, 1997 BSD