01-24-2008
Quote:
Originally Posted by
Ume1986
hi all..
I dont know how to search for a string in a file.. I have tried doing.. I did google but didnt get effective answers..my code is as follows:
int search(char* filename,const char*
username,const char* passwd)
{
int flag=0;
unsigned long fsize=0;
unsigned long current=0;
int fdsearch=-1;
int cun,cpw;
char *user,*pass;
int un,pw;
pw=strlen(passwd);
un=strlen(username);
fdsearch=open(filename,O_RDONLY);
fsize = lseek(fdsearch, 0L, 2);
user=(char*)malloc(un);
pass=(char*)malloc(pw);
while (current<fsize)
{
lseek(fdsearch,current,SEEK_SET);
cun=read(fdsearch,user,un);
lseek(fdsearch, cun+1, SEEK_SET);
cpw=read(fdsearch,pass,pw);
if(!memcmp(username,user,un))
{
if(!memcmp(passwd,pass,pw))
{
flag=1;//found
close(fdsearch);
return(flag);
}
printf("incorrect password");
close(fdsearch);
return(flag);
}
//increment current position by 1
current++;
}//while
return flag;
}
I dont know how to read end of string(space will be the delimiter in the file),then end of line.
i guess the bolded areas are where I am doing mistakes..
kindly help me...
thanks in advance
Does you input file contains only one username/password pair or mutliple entries?
Thanks
Nagarajan G
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I need a script to get every line from a file where there are less then
17 ; on a line.
Thank's (5 Replies)
Discussion started by: VODAFUN
5 Replies
2. Shell Programming and Scripting
Shell script help
Here is 3 sample lines from a log file
<date> INFO <java.com.blah> abcd:ID= user login
<date> DEBUG <java.com.blah> <nlah bla> abcd:ID=123 user login
<date> INFO <java.com.blah> abcd:ID=3243 user login
I want to find unique "ID" from this log... (3 Replies)
Discussion started by: gubbu
3 Replies
3. Shell Programming and Scripting
What would be the most succinct way of doing this (preferably in 1 line, maybe 2):
searching the first 10 characters of every line in a text file for a specific string, and if it was found, print out characters 11-20 of the line on which the string was found.
In this case, it's known that there... (13 Replies)
Discussion started by: busdude
13 Replies
4. UNIX for Dummies Questions & Answers
What's the best way to find a string in a very long file without newlines in Unix? The standard utility I'm aware of for finding a string in a single file is grep, but for a long file without newlines, I think the output is just going to be the input. I suppose I could use sed to replace the... (5 Replies)
Discussion started by: aaronpoley
5 Replies
5. Shell Programming and Scripting
As i am new to unix so facing some problems in scripting:
here is my question:
i m having two files. 1st file say a.txt contain 3 column like
SPECIALITY|UMP_CODE|SPECIALTY_CODE
Addictive Diseases|25ADD|ADD
Addictive Diseases/Family Practice|25ADD|ADD/FP
Aerospace Medicine|1.041666667|AM... (4 Replies)
Discussion started by: dsh007
4 Replies
6. Shell Programming and Scripting
Hi, I have a single colum file and I need to reformat the file so that it creates a new line every time it come to an IP address and the following lines are corresponding rows until it comes to the next IP address.
I want to turn this
172.xx.xx.xx
gwpusprdrp02_pv
seinwnprd03... (7 Replies)
Discussion started by: kieranfoley
7 Replies
7. UNIX for Dummies Questions & Answers
Hi,
I have a very large file that contains a listing of all files on the system. I need to create a listing from that file of all files that start with the following format: s???_*, whereas the '?' represents characters, so the file name begins with an 's' followed by three other characters and... (4 Replies)
Discussion started by: tes218
4 Replies
8. Shell Programming and Scripting
Hello All,
I have a text file, i want to search for a string in it and the string is repeated multiple times in a file i want to get the first occurence of the string in a variable.
the content of file is like:
I want to grepthe first occurance of "Configuration flow done" and store the... (7 Replies)
Discussion started by: anand2308
7 Replies
9. Shell Programming and Scripting
I'm interested in writing a report script using BASH that searches all of the files in a particular directory for a keyword and printing a list of files containing this string...
In fact this reporting script would have searches for multiple keywords, so I'm interested in making multiple... (2 Replies)
Discussion started by: chemscripter904
2 Replies
10. UNIX for Beginners Questions & Answers
Text in input file is like this
<title>
<band height="21" isSplitAllowed="true" >
<staticText>
<reportElement
x="1"
y="1"
width="313"
height="20"
key="staticText-1"/>
<box></box>
<textElement>
<font fontName="Arial" pdfFontName="Helvetica-Bold"... (4 Replies)
Discussion started by: aankita30
4 Replies
LEARN ABOUT DEBIAN
context_type_set
context_new(3) SELinux API documentation context_new(3)
NAME
context_new, context_str, context_free, context_type_get, context_type_set, context_range_get, context_range_set,context_role_get, con-
text_role_set, context_user_get, context_user_set - Routines to manipulate SELinux security contexts
SYNOPSIS
#include <selinux/context.h>
context_t context_new(const char *context_str);
const char * context_str(context_t con);
void context_free(context_t con);
const char * context_type_get(context_t con);
const char * context_range_get(context_t con);
const char * context_role_get(context_t con);
const char * context_user_get(context_t con);
int context_type_set(context_t con, const char *type);
int context_range_set(context_t con, const char *range);
int context_role_set(context_t con, const char *role);
int context_user_set(context_t con, const char *user);
DESCRIPTION
These functions allow an application to manipulate the fields of a security context string without requiring it to know the format of the
string.
context_new
Return a new context initialized to a context string
context_str
Return a pointer to the string value of the context_t Valid until the next call to context_str or context_free for the same context_t*
context_free
Free the storage used by a context
context_type_get, context_range_get, context_role_get, context_user_get
Get a pointer to the string value of a context component
NOTE: Values returned by the get functions are only valid until the next call to a set function or context_free() for the same context_t
structure.
context_type_set, context_range_set, context_role_set, context_user_set
Set a context component
RETURN VALUE
On success, zero is returned. On failure, -1 is returned and errno is set appropriately.
SEE ALSO
selinux(8)
dwalsh@redhat.com 20 December 2011 context_new(3)