Programming :: Tell If Grep Didn't Return Anything?
Mar 15, 2011
I have a file:
979798707
787862348
766428634
I want to see if all the records in the file are present in the contents of the files of a particular directory.
Basically I want to say if grep doesn't return anything, then report.
For example in /tmp dir I have 4 files and flast 2 values (787862348 and 766428634) are present in the files of /tmp dir, but first one (979798707) is not. I want to echo that in a reporting file.
something like:
while read line
do
# if ! grep -rl $line /tmp
echo $line >> are_not_present
done < "myFile"
How do I achieve " if ! grep -rl $line /tmp"? That is, if the line is found by grep, then grep will print the output, but if grep does'nt find it, it will print nothing. How can I check if grep didn't find it (i.e. printed nothing)?
View 2 Replies
ADVERTISEMENT
Jan 13, 2011
I have a mail.log file, of which I want to redirect only the search strings of the sender from=<example.sender@exampledomain.com> and the size size=4537 to a file.
In every case the sender string starts as from=<> and the size string starts as size=
What would be the grep command to redirect only the two search strings to a .txt file?
View 2 Replies
View Related
Jun 13, 2011
I have ASCII files to parse that 48 hours old or more ; I can identify them like so
Code:
find . -name "FILE*TXT" -mtime +1 -exec ls -ltas '{}' ';'
Some files have a list of hardware errors (we test electronic components), some have none. If the file name has no errors, I still want to display a message like so
Code:
grep ^err R*VER && echo "No error"
FILEA.TXT:err->USB3910err
FILED.TXT:err No Error
This grep statement works but it seemingly overrides the find() statement above if I run both at the same time... How can I combine the two statements to create a report that lists the filename and error(s) like so
Code:
FILEA.TXT Button3320err
FILEB.TXT USB3235err
FILEC.TXT IR Remote2436err
FILED.TXT No error
Is it possible to return "No error" with the file name without error?
View 11 Replies
View Related
Nov 22, 2010
I need to kind of grep within grep. My input file would be something like:
[Code]....
and I need to find the first occurrence of hello before MY PATTERN (hello 9008 in this case), so the output should be:
[Code]....
View 4 Replies
View Related
Jun 30, 2010
I trying to write a UART(interfacing of serial devices) to linux machine but after I execute the following code to receive data I need to enter key (carriage return).... but I don't want to remove carriage return/enter key
[Code]....
View 13 Replies
View Related
Sep 24, 2010
I have a script put in cron.daily and edit the var/spool/cron/crontabs/root file with this text
Code:
View 1 Replies
View Related
Feb 9, 2011
I recently noticed some of my one-liners with && and || didn't work as I expected so I googled for "bash && || pitfalls" and found this page [URL] It's probably my fault, but I still don't understand why it wouldn't work as I want it..... I don't even have the code anymore that wasn't working properly because I rewrote it using if ; then ; command ; fi
View 4 Replies
View Related
Jul 27, 2010
I make personal site with php on wamp. When uploaded it to my debian box I make some comments in index.php like
Code:
//include(realpath('inc/inc.php'));
echo realpath('inc/inc.php');
upload the changed php file, but when try to reload the site same errors stay there. There is some cache that I have to clear but I don't know where it is. In wamp I clear wamp mp* directory What cache I have to clear? Edit: It is not my browser. I use firefox and clear everything with several times ctrl+shift+del I even delete index.php but the same errors stay at the page:
Code:
Warning: include(inc/inc.php) [function.include]: failed to open stream: No such file or directory in /var/www/site/index.php on line 3 Warning: include() [function.include]: Failed opening 'inc/inc.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/site/index.php on line 3
View 1 Replies
View Related
Oct 12, 2010
i am having two small issues with a function i have made.sorry if it is a mess, i am still learning bash.the first is calling the nonpersistssh function (second line) and assigning the return value to nonpersistdiag.the function returns 1, but nonpersistdiag seems to only contain 0. i am unsure on how to proceed.the second problem is the nested else clause on line 10. it is a syntactical error. how would i declare it correctly?
Code: function endsession(){
nonpersistdiag=$[nonpersistssh]# a function that returns an exit code
sudo /etc/init.d/ssh stop; sshdiag=$?
[code]....
View 6 Replies
View Related
Jun 3, 2011
What are the uses of return 0, return 1 and exit statements in C
View 4 Replies
View Related
Nov 15, 2010
On this link [URL]4 a return type is defined
Code:
return ((unsigned int)(unsigned long)base & TBASE_DEFERRABLE_FLAG);
What is the above function returning.I am not clear with definition of what is being returned in the above code.
View 7 Replies
View Related
Jan 18, 2010
I'm confused about what "echo $0" in a shell actually return. Consider these tests:
Code:
[root@e11apvl151 ~]# # Login shell:
[root@e11apvl151 ~]# echo $0
-bash
[root@e11apvl151 ~]# # Starting a new shell
[root@e11apvl151 ~]# bash
[root@e11apvl151 ~]# echo $0
bash
[root@e11apvl151 ~]# screen
[root@e11apvl151 ~]# echo $0
/bin/bash
Depending on wether the shell is a login shell, a regular shell, or a screen utility, I get different results.
View 8 Replies
View Related
Dec 16, 2010
I'm reading a text file with fscanf using a loop until feof(inFile). How can I return to the top of the file? As in I have one loop that scans until the eof and then after it there's another loop and I want to start from the beginning of the file again scanning to the end of it. How do I get back there?
View 3 Replies
View Related
Jan 11, 2010
I am testing the serial ports on a Single Board Computer(SBC) running Linux kernel 2.6.29. I usually do this by connecting the serial port to another PC serial port, then doing "cat /dev/ttyS0" on PC and "echo hello > /dev/ttyS0" on the SBC. However in the current system, "echo hello > /dev/ttyS0" command does not return at all! Also no characters appear on the destination port. I am running the echo command as root. The system boot messages show that the serial port in indeed /dev/ttyS0.
View 2 Replies
View Related
Mar 10, 2010
I think my title pretty much explains it. I am writing a script and I want to start a program in the background, and when that program finishes I want to check the return value to make sure there was no error.For example normal I would do something like this:
#!/bin/sh
program
if [ ! $? -eq 0 ]; then
echo "There was an error"
exit 1
fi
Now I want to do something like this:
#!/bin/sh
PRTN=`program1 &`
program2
if [ ! $? -eq 0 ]; then
[code]....
In this case if program2 finishes before program1, I don't think the return value from program1 $PRTN would be valid at the time it is checked.
View 3 Replies
View Related
Aug 5, 2010
I am using pthread_create system call to create a thread. However pthread_create does not return the PID ( process ID). Is there any quick way to fınd the PID of the created thread.
View 1 Replies
View Related
Mar 19, 2011
C++ code:
Code:
#include<fstream.h>
[code]....
View 4 Replies
View Related
Mar 10, 2010
I write a little script by bash.
#!/bin/bash
a=`gawk '/Iterations /{print $0}' hoge.log | gawk 'BEGIN{FS=" "}{print ($4)}'`
a=`expr 3 '*' $a`
[code]...
View 13 Replies
View Related
Jan 25, 2010
I have always encountered this problem in ubuntu bash shell scripts that echo command in a function will be treated as a return value when used in a function. e.g.
[code]...
The output would simply be xyz. Hence the echo seems to function as a "return" command when used in a function with a return value.
View 4 Replies
View Related
Feb 23, 2010
$val = mkdir $directory, 755
print $val;
does't create directory but return as value '0'
[code]....
View 2 Replies
View Related
Jun 14, 2010
I have confusion regarding pthreads return value. All in short, is the is a valid return value ?
[source]
void * myThrRoutine(void *arg)
{
struct myStruct **myst = (struct myStruct**) arg;
cout<<"In thread "<<(*myst)->var<<(*myst)->msg<<endl;
int x = 20;
pthread_exit((void*)x);
}
[/source]
This seems to work fine on pthread_join , but I want to ensure it is not by chance.
View 1 Replies
View Related
Jun 13, 2010
But it's been hell finding an answer, or I just don't know what to look for..I have a prompt that asks for a float, and if the user doesn't put in a valid number, then it should die with an error message.
Code:
def die_with_error():
print 'ERROR: You didn't specify a valid number!'
[code]....
View 2 Replies
View Related
Feb 8, 2011
A friend working in HPC environments commented me that he had an issue regarding the use of the malloc() function.What issue?He told me that he has had cases in where malloc() instead of returning a NULL pointer on failure, simply didn't change the original value of the pointer it was trying to use for allocation, thus forcing him to initialize pointers to be allocated with malloc() to NULL, so that he could be sure that if malloc() fails, a test for NULL would make sense.
View 12 Replies
View Related
Jul 9, 2010
I have an a script in /etc/rc.d/init.d script that I would like to start and stop my sample application. I have named my script "foo", then I can start running my application my typing $ foo start but this does not return [OK] like other scripts do and does not return to shell prompt. My application is basically like this
int main()
{
do {
printf("Hi
");
sleep(1);
} while (1);
}
What is missing from my application that prevents from returning the shell prompt?
View 3 Replies
View Related
Jul 15, 2010
I'm getting some information about C language and this session of a C book (follow the above link) is using a bad example for me. When I'm trying this example of function returning a pointer, my compiler is stating a warning that I return a pointer to a local variable. I realized that it is error prone after all this variable may be override before the function has done his execution. And the author is fooling me saying that this example is "perfectly safe". I'm wrong? There is something that I don't got yet? Sorry but this site is preventing me to post the link of book cause I'm a newbie, so a need the hack it. Just strip out the question signs:
{LINK}
?w?w?w
?cs.cf.ac.uk?
[code]....
View 6 Replies
View Related
Feb 1, 2010
I have functions which return different data like: int, char*, double...
I also have a list of datatypes (INTEGER, TEXT, REAL...) which can be returned.
I need to map a datatype with function, which purpose is to return it. Therefore, when I determine a datatype, I would like to call the required function without doing switch all the time.
My idea is to have an array of structs like this:
Code:
struct type_func_map
{
int type;
void (*func_wrapper_int)(void); //void (*func_wrapper_text)(void); void (*func_wrapper_real)(void);
};
[Code].....
View 10 Replies
View Related
Aug 8, 2010
I have a script that reads part of a line, delimited between the first and second intended part by a colon. Then it "chops" the part after the colon, which are words offset by commas (counting them beforehand so as to catch every word in the string's second part), like this:
Code:
"COLORS.JPG:red,orange,yellow,green,"
(Returning)
red
[code]....
single script that parses/breaks both parts of a line like this "COLORS.JPG:red,orange,yellow,green;blue,indigo,violet," so that the two parts, separated into single words (or two and three words, sometimes with spaces) can be used as single-line annotations and written to JPEG files using Exiv2. So far, I haven't been able to come up with a script that does this without one part of the total string(usually that part after the colon) becoming the first word in the second array. In other words, I look for this:
KEYWORDS:
[ ]red
[ ]orange
[ ]yellow
[code]....
Or vice-versa (ie, the second array winds up as a single-line "member" of the first). I think it's because I'm using a single while read loop to read the text file in which the filenames and substrings happen to be. If there's some way of reading a file once and going back to the beginning to read it again in another while loop, I haven't found it.
View 14 Replies
View Related
Oct 30, 2010
I have a function that returns a boolean value, True of False. Is there any convention whether 0 = False or 0 = True? It should be obvious, 0=False, 1=True. However programs usually return 0 on success and reserve higher numbers for error values. I.e. if the program finishes successfully (function int main() finishes successfully ), it returns 0 - and that contradicts that 0 should be false.
And especially if I want a function to do some computations on parameters passed by reference and return success status. Should it return 1 (true) for success, or should it return 0 for success - like any Unix program does?
Is there any convention for this?
View 1 Replies
View Related
Oct 21, 2010
I'm witting a piece of code that needs to read key presses. However I cannot use them as stream, but rather need discrete reads. The code is to simulate an io board interface. So When I press say "d" I need to read it in instantly, not wait for return. I've tried sdl, but no luck (I'm reading in a thread and it causes some problems) I'm using linux so can't use conio.h functions, I've tired gatch from cureses but this still waits for return.So in C/c++ is there a way I can read instant key presses.
View 1 Replies
View Related
Apr 7, 2011
I am want get next information: Get process statistics from kernel and return them buf as
Quote:
number of processes : ticks_user : ticks_system : ticks_interrupt : cpuseconds : procsizes : resident segment sizes I am find some this information in /proc/[pid]/stat, but there are is not data about ticks system, ticks_interrupt, cpusecond. Where I am can find it information???
I am write on C, better if it will file witch information, and not programm.
View 2 Replies
View Related