Modifying the shell script to select pattern

Hello,
I have script which work 70% of the desired task [1], the output from script.sh is following [2], however the desired output I require is following [3].

Any piece of suggestion would be great..

thanks in advance,
emily

[1]

#!/bin/bash                                                                                                                                                                
PATHNAME=$1
CONSTANT=rfio:
GREP=$2
OUTPUT=$3

voms-proxy-init --voms cms:/cms/dcms

echo "Copying \"$1 | grep $2\" to $3"                                                                      
srmls "$PATHNAME" | grep "$2" | awk '{print string path $2}' string="" path=""  > "$3"

echo "progressing ... please be patient...

"[2]

/pnfs/desy.de/cms/tier2/store/user/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_L1RECO_L1/150201_151524/0000/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_199.root
/pnfs/desy.de/cms/tier2/store/user/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_L1RECO_L1/150201_151524/0000/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_746.root
/pnfs/desy.de/cms/tier2/store/user/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_L1RECO_L1/150201_151524/0000/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_92.root

[3]

/store/user/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_L1RECO_L1/150201_151524/0000/SingleMuMinus_Winter15_FlatPt-0\
to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_199.root
/store/user/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_L1RECO_L1/150201_151524/0000/SingleMuMinus_Winter15_FlatPt-0\
to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_746.root
/store/user/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Winter15_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_L1RECO_L1/150201_151524/0000/SingleMuMinus_Winter15_FlatPt-0\
to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_92.root

Hello emily,

Can I check the logic rules you want to apply first? I think that you want to take each record and:-

  • remove the first four directory layers
  • split the line after ....Winter15_FlatPt-0 adding in a backslash

I regret that I do not know srmls as a command. Is this another script?

Robin

First, you want to chop off 3 dirs; cut, sed, awk or even just shell pattern chopping (${name#pattern}, ${name%%pattern} ) can do this.

Second, you want to add a line break before 'to200', and again, sed, awk or shell pattern chopping. See man bash look for %%:

The sed/awk '.*' is always aggressive, but the pattern chop allows you to select aggressive or minimal wild card. I faintly recall MULTICS qedx or Waterloo FRED allowed you to select, too.

My mnemonic for remembering them is "#" is pound like 'pound on the nose", and '%' is like for a broker or artistliving off royalties, 'take my percentage at the end'.

1 Like

DGPickett, your mnemonics are great!

My guess for the splitting requirement is lines are to be split with "\" if they exceed 170 characters.

This could be achieved with:

srmls "$PATHNAME" | sed -En -e 's:^(/[^\/]+){4}::' -e "/$GREP/"'s/.{170}/&\\\n/gp'

I had it explained that in monetary values, the pound sign (okay, that's not # ) goes at the beginning and working with percentages, the % goes at the end.

Pardon me for being picky about the British pound . The # is a hash.

Robin - British, in case you couldn't guess!

Well, # is just pounds of weight, force, mass, but the funky elle is pounds sterling. Is the price of silver really tied to it? Let me check my Yahoo finance metals prices! $16.95 an ounce is $271.20 / # with the GBP at $1.5364, 17651 % inflation!

The funky L? I say, the Pound from the United Kingdom of Great Britain and Northern Ireland is not a mere token or plaything (trying to sound indignant)

We're off the gold standard ages ago (I never remember it) but the GBP is sacred to some of us.

You'd be over 100 if you did: Pound sterling - Wikipedia, the free encyclopedia :smiley: