1827862 Members
2166 Online
109969 Solutions
New Discussion

Complex grep command

 
SOLVED
Go to solution
panchpan
Regular Advisor

Complex grep command

Hello.
Could you please help me in understanding what below commands would do - I get lost somewhere:

1)
grep -q $prebase `awk '{ if (/DB\.pf/)
{ ncol=split($2,tab,"/"); printf("%s ",tab[ncol]) } }' *SV.pf`

2)
probkup $base $OPTION /dev/null -estimate -vs $vol_size|
awk -v nombkup=$ARCH_BKUP/$nombkup '{
if (/volumes are req/) nbvol=10}
END { for(i=1;i printf("%s.%d.bkp\n",nombkup,1+i) }' > $ARCH_BKUP/VOL.BKP
NBVOL=`awk 'END { print NR+1 }' $ARCH_BKUP/VOL.BKP`


Thank you!
3 REPLIES 3
Peter Nikitka
Honored Contributor

Re: Complex grep command

Hi,

1) part1:
awk '{ if (/DB\.pf/) ... ' *SV.pf
Examines files *SV.pf for lines containing 'DB.pf'.
part2:
ncol=split($2,tab,"/"); printf("%s ",tab[ncol])
Takes the second field, which seems to be a pathname, extracts and prints the pure base filename.
part3: grep -q $prebase ``
Sets just a return value if $prebase is found in the above printed filenames

2 (which is not a grep and seems not really reasonable to me :-)
part1:
Analyses the output of the commamd 'probkup',
if it contains the string 'volumes are req'.
part2:
If that is true, 9 lines are printed to a file of the format (variables expanded)
$ARCH_BKUP/$nombkup.2.bkp
...
$ARCH_BKUP/$nombkup.10.bkp
part3:
Variable NBVOL is set to the number of lines of this file +1.
The result will be 1 (no match in part1) or 10 (any number of matches in part1).

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
panchpan
Regular Advisor

Re: Complex grep command

Hello.

Could you also please help me in understanding below command :

if ! tar xf $SOURCE `tar tf $SOURCE | grep '^ipasii'`
then
echo "not success"
fi

Thank you!
Peter Nikitka
Honored Contributor
Solution

Re: Complex grep command

Hi,

regarding your tar:
part1) .. `tar tf ... | grep '^..'`
The command in the backtics lists the content of $ARCHIVE and filters out filenames starting with 'ipasii'

part2) tar xf ``
The above filename are fed into tar for restore

part3) if ! tar
If the tar failes, an error message is echoed.

CAUTION:
There will be no message or error reported, when NO name of the form of part1 is found in the tar archive: Having write access to the target, all files of the archive would be extracted!
I don't think, the writer of this piece of code intended this to do ...

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"