[gentoo-user] bash script question

2014-08-18 Thread Adam Carter
I want to use an if/then that tests for the existence of a string in 4 files. Usually I do this by checking the exit code of grep, when i'm checking a single file. However, I cant get the syntax right for multiple checks. To troubleshoot I’ve dropped back to just checking two files, and i’ve

Re: [gentoo-user] bash script question

2014-08-18 Thread wraeth
On Mon, 2014-08-18 at 18:54 +1000, Adam Carter wrote: But this matches if grep fails both times as well as when it matches both time. Any ideas? If you don't mind using a quick loop, you could use something like: n=0 for f in file1.txt file2.txt file3.txt file4.txt; do grep 'string' ${f}

Re: [gentoo-user] bash script question

2014-08-18 Thread Stroller
On Mon, 18 August 2014, at 10:42 am, wraeth wra...@wraeth.id.au wrote: On Mon, 2014-08-18 at 18:54 +1000, Adam Carter wrote: But this matches if grep fails both times as well as when it matches both time. Any ideas? If you don't mind using a quick loop, you could use something like: n=0

Re: [gentoo-user] bash script question

2014-08-18 Thread wraeth
On Mon, 2014-08-18 at 12:29 +0100, Stroller wrote: On Mon, 18 August 2014, at 10:42 am, wraeth wra...@wraeth.id.au wrote: I propose addressing this with an array of the filenames. Thus additional files can be added for testing, without manual adjustment of the expected total. +1 I

Re: [gentoo-user] bash script question

2014-08-18 Thread Kerin Millar
On 18/08/2014 12:29, Stroller wrote: On Mon, 18 August 2014, at 10:42 am, wraeth wra...@wraeth.id.au wrote: On Mon, 2014-08-18 at 18:54 +1000, Adam Carter wrote: But this matches if grep fails both times as well as when it matches both time. Any ideas? If you don't mind using a quick loop,

Re: [gentoo-user] bash script question

2014-08-18 Thread Stroller
On Mon, 18 August 2014, at 12:58 pm, wraeth wra...@wraeth.id.au wrote: ... I've never been overly familiar with bash arrays (I tend towards python or perl if I need anything even starting to get complex); Indeed, I had to look up the syntax from my own snippets folder, myself. I need to

Re: [gentoo-user] bash script question

2014-08-18 Thread Stroller
On Mon, 18 August 2014, at 1:16 pm, Kerin Millar kerfra...@fastmail.co.uk wrote: ... (( count += matches )) done (grep -hcm1 -F $string ${files[*]}) Oh, this is lovely. I've learned some things today. if (( count == ${#files[@]} )); then May I ask why you prefer these

Re: [gentoo-user] bash script question

2014-08-18 Thread Kerin Millar
On 18/08/2014 15:02, Stroller wrote: On Mon, 18 August 2014, at 1:16 pm, Kerin Millar kerfra...@fastmail.co.uk wrote: ... (( count += matches )) done (grep -hcm1 -F $string ${files[*]}) Oh, this is lovely. I've learned some things today. if (( count == ${#files[@]} ));

Re: [gentoo-user] bash script question

2014-08-18 Thread Kerin Millar
On 18/08/2014 15:18, Kerin Millar wrote: On 18/08/2014 15:02, Stroller wrote: On Mon, 18 August 2014, at 1:16 pm, Kerin Millar kerfra...@fastmail.co.uk wrote: ... (( count += matches )) done (grep -hcm1 -F $string ${files[*]}) Oh, this is lovely. I've learned some things

[gentoo-user] bash script question, strange grep

2005-04-18 Thread Botykai Zsolt
Hi 4 everyone, I have a little problem: i have a file list in /tmp/iadmos (contains 28 file name which are in the current directory, i made this list with: egrep -il 'trt_attr.*[,]iadm' t*.dcl /tmp/iadmos then I want to cut out the files which don't contain the string 'NOIADM'. So I did:

Re: [gentoo-user] bash script question, strange grep

2005-04-18 Thread Edward Catmur
then I want to cut out the files which don't contain the string 'NOIADM'. So I did: for i in `cat /tmp/iadmos` ; do egrep -lv 'NOIADM' $i ; done which gave me all 28 file name. I wondered about it, so I tried: for i in `cat /tmp/iadmos` ; do egrep -l 'NOIADM' $i ; done which gave