0

I am creating a shell script to take input from CSV files, having two rows ( One Column mentioning time and another file string ).. My script works when there is one row... But it isnot working in multiple rows and also how can i know which row it is searching didnt got the files .

Sample file:

1300,N213
1245,N218
1400,N222
1600,N225

Code, I am trying to make it work.

#!/bin/bash
tr_filepath=/var/opt/data/nms_umts_pms_seg/segment1/
echo "Folder to search for traces ${tr_filepath}"
tr_newpath=/var/opt/ericsson/nms_umts_pms_seg/segment1/edos/4G/
CNTRL_FILE=/home/vx622325/filematch.csv
echo "File Contents of ${CNTRL_FILE} to match with pattern"

for i in $CNTRL_FILE;
do

  t=$(cat $i | awk -F"," '{ print $1}')
  n=$(cat $i | awk -F"," '{ print $2}')
  X=`find "$tr_filepath" -type f -iname "A*."$t"*,*="$n"*.bin.gz"`
  echo -e "Traces To Copy \n $X\n" >> /home/vx622325/result_`date +"%d_%m_%Y"`.csv


if [ -d "$tr_newpath" ]; then
        y= cp -rp $X $tr_newpath
else
        echo "Output folder $tr_newpath not found" > /home/vx622325/result_`date +"%d_%m_%Y"`.csv

fi
done

Files to search for

A20190118.2200+0300-2201+0300_SubNetwork=ONRM_RootMo,SubNetwork=N213,MeContext=N213,ManagedElement=1_rnc_gpehfile_Mp0.bin.gz
A20190118.2200+0300-2201+0300_SubNetwork=ONRM_RootMo,SubNetwork=N213,MeContext=N213,ManagedElement=1_rnc_gpehfile_Mp10.bin.gz
A20190118.2200+0300-2201+0300_SubNetwork=ONRM_RootMo,SubNetwork=N213,MeContext=N213,ManagedElement=1_rnc_gpehfile_Mp11.bin.gz
0

I hope the issue is with your input to for loop. you are giving input as filename rather than the content of the file.

Try as below

for i in `cat $CNTRL_FILE`
  • Thankyou, How can i make the find to read each line by line ??? – Indranil Jan 23 '19 at 6:13
  • @Indranil couldn't get u.. – msp9011 Jan 23 '19 at 7:04
  • Output after making the changes as for i in cat $CNTRL_FILE Output: vx622325@ran6adm2:~$ ./edsodp_copy_traces_script_new_1.sh Folder to search for traces /var/opt/data/nms_umts_pms_seg/segment1/ File Contents of /home/vx622325/filematch.csv to match with pattern cat: cannot open 1300,E-BTM623MLX: No such file or directory cat: cannot open 1300,E-BTM623MLX: No such file or directory ./edsodp_copy_traces_script_new_1.sh: line 18: /usr/bin/cp: Arg list too long – Indranil Jan 23 '19 at 7:34
0

As mentioned by msp9011, problem is with

for i in $CNTRL_FILE 

where file name is given where as you should be giving content of the file. Easy way is to ready file setting the internal field separator (IFS) as following

while IFS=, read -r column1 column2
do
    echo "column1 : $column1, column2 : $column1"
    #Take action using input
done < $CNTRL_FILE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.