You are not logged in.

#1 2011-10-08 22:08:37

gromlok
Member
Registered: 2010-04-19
Posts: 154

null

null

Last edited by gromlok (2019-03-10 15:50:14)


.

Offline

#2 2011-10-09 02:26:44

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: null

I) Regarding your if statement, you could do something like this:

estr='FILE: %s does not exist or does not have %s permissions.\n'
[ -r $inputfile ] || ( printf "$estr" "$inputfile" "read" && exit 1 )
[ -w $outputfileNOM ] || ( printf "$estr" "$outputfileNOM" "write" && exit 1 )
[ -w $outputfilePGP ] || ( printf "$estr" "$outputfilePGP" "write" && exit 1 )

II)The -r/-w/-x mean that the file has the read/write/execute bit set. Do a

$ man chmod

for details.

III) You should be able to do

if [[ "$line" =~ .*\<NV\> ]]; then
	echo "..."
	(( countNOM++ ))
fi

but that didn't work for me when I tried it.  I don't know if this is a bug in bash, or (more likely) something that I am doing wrong.

Regardless, I would write your script like this:

#!/bin/bash

file=$(egrep '^[A-Z]..[0-9]{2}' "$1")
grep '\<NV\>' <<< "$file" > "$2"
grep '\<PV\>' <<< "$file" > "$3"

echo 'Count NON:' $(wc -l < "$2")
echo 'Count PGP:' $(wc -l < "$3")

Note: In reading your script, your comments imply that each line of the input file starts with 'llnnn' but the example line you gave starts with 'lllnn'.  That is, there are 3 letters (AVO) followed by 2 numbers (01). The above script assumes that lines start with 'lllnn'

Offline

#3 2011-10-09 03:30:46

gromlok
Member
Registered: 2010-04-19
Posts: 154

Re: null

null

Last edited by gromlok (2019-03-10 15:50:26)


.

Offline

#4 2011-10-09 06:07:54

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: null

exit isn't working because it's in a subshell started by ( ). What you want to use is { }, note that it needs to end in a ;

Compare:

( exit )
{ exit; }

Offline

#5 2011-10-09 17:15:07

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: null

Well, I originally wrote

[ -r $inputfile ] || { printf "$estr" "$inputfile" "read" && exit 1 }

but that didn't work for me, so I put it in () which did work.  I have played around with it a little this morning and I got the following to work:

[ -r $inputfile ] || { printf "$estr" "$inputfile" "read" && exit 1; }

You need a ';' at the end (at least I did).

Edit: I see Procyon indicated the ';' at the end in his (her?) example.  I guess I wasn't aware of that.

Last edited by rockin turtle (2011-10-09 17:38:05)

Offline

#6 2011-10-09 17:25:32

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: null

gromlok, I just read the bash FAQ you linked to, and I believe the following will work.

NOM='\<NV\>'
if [[ "$line" =~ $NOM ]]; then
	echo "..."
	(( countNOM++ ))
fi

They (the \< and \>) indicate that the 'NV' can't be contained in another word.

Offline

#7 2011-10-09 18:37:42

gromlok
Member
Registered: 2010-04-19
Posts: 154

Re: null

null

Last edited by gromlok (2019-03-10 15:50:35)


.

Offline

Board footer

Powered by FluxBB