You are not logged in.
Pages: 1
null
Last edited by gromlok (2019-03-10 15:50:14)
.
Offline
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
null
Last edited by gromlok (2019-03-10 15:50:26)
.
Offline
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
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
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
null
Last edited by gromlok (2019-03-10 15:50:35)
.
Offline
Pages: 1