awk seems to be wrongly placed?

Dear all,
I have small script ( which after introducing few changes) is not working as desired way [1].

The content of the output file from this script is following
-----------

    1492033600 /pnfs/desy.de/cms/tier2/store/user/emily/L1Trigger/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Fall14_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_RECO_L1/150127_084421/0001/SingleMuMinus_Fall14_FlatPt-0to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_1271.root
      1487504182 /pnfs/desy.de/cms/tier2/store/user/emily/L1Trigger/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Fall14_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_RECO_L1/150127_084421/0001/SingleMuMinus_Fall14_FlatPt-0to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_1994.root

However, I wanted the 'AWK' command to work and provide me following output:

---------------/store/user/emily/L1Trigger/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Fall14_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_RECO_L1/150127_084421/0001/SingleMuMinus_Fall14_FlatPt-0to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_1271.root
 /store/user/emily/L1Trigger/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Fall14_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_RECO_L1/150127_084421/0001/SingleMuMinus_Fall14_FlatPt-0to200_MCRUN2_72_V1_GEN_SIM_DIGI_RECO_L1_1994.root

Please suggest what went wrong..? :frowning: :frowning:
emily,

[1]
------------------------------

#!/bin/bash                                                                                                                                                                                                    

OUTPUT=InputFile_
GREP=root
EOSPATH="srm://dcache-se-cms.desy.de:8443/pnfs/desy.de/cms/tier2//store/user/emily/L1Trigger/HOUpgrade/Generation/SingleMuonGun/SingleMuMinus_Fall14_FlatPt-0to200_MCRUN2_72_V3_GEN_SIM_DIGI_RECO_L1/150127_\
084421/"
FILEPATH[1]=$EOSPATH/0001
#FILEPATH[2]=$EOSPATH/0002                                                                                                                                                                                     
                                                                                                                                                                      
### copy the FileName from eos to $3                                                                                                                                                                           
CopyFileNameFromCastor()  {
    for FileNameIndx in "${FILEPATH[@]}"
    do
        if [[ ! -e "dest_path/$FileNameIndx" ]]; then
            Index=$(echo $FileNameIndx | awk '{split($FileNameIndx, a, "/00"); print "0"a[2]}')
            echo "Copying fileName \"$FileNameIndx  | grep root\" to $OUTPUT$Index"
            srmls $FileNameIndx --count 99999 --offset 2 | grep "$GREP" | awk -F'tier2' '{print string path $GREP}' string="" path=""  > $OUTPUT$Index
            FINALFILE=$OUTPUT$Index

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

            ### split the files into small files for job submittion                                                                                                                                            
            awk '                                                                                                                                                                                              
            NR==1 {outfile = sprintf("%s_%01d.txt", FILENAME, 0)                                                                                                                                               
            }                                                                                                                                                                                                  
            {print > outfile                                                                                                                                                                                   
            }                                                                                                                                                                                                  
            (NR % 200) == 0 {                                                                                                                                                                                  
            close(outfile)                                                                                                                                                                                     
            outfile = sprintf("%s_%01d.txt", FILENAME, int(NR/200))                                                                                                                                            
            }'  $FINALFILE
        fi
    done
    rm -f ${OUTPUT}*[0-9][0-9][0-9]
}

---------- Post updated at 08:24 AM ---------- Previous update was at 08:15 AM ----------

I modified this as following:

            srmls $FileNameIndx --count 99999 --offset 2 | grep "$GREP" | awk '{split($FileNameIndx, a, "tier2"); print a[2]}' > $OUTPUT$Index

ans its working fine...:slight_smile: :slight_smile: