Quantcast
Channel: Struggling with output of grep into an array - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 2

Struggling with output of grep into an array

$
0
0

Please note I'm not a developer but I have requirements where I'm trying to search an SVN repository for files containing certain table names. I have built this script on the basis of many things I have read here.

printf "table_name, file_name, full_path\n" >> export_list.txt
while read table
do
extract=($(egrep -ilrs $table /path/to/file | egrep -i tag | egrep -v backup))
file_name=$(basename $extract)
printf "$table, $file_name, $extract\n" >> export_list.txt
done < table_list.txt

I am expecting output like this

table_name, file_name, full_path
SOMETABLENAME, SomeFileName, /path/to/file/tag1.0/SomeFileName
SOMETABLENAME, SomeFileName, /path/to/file/tag2.0/SomeFileName
SOMETABLENAME, SomeFileName1, /path/to/file/tag1.0/SomeFileName1
SOMETABLENAME, SomeFileName1, /path/to/file/tag2.0/SomeFileName1

Instead I am only getting one line back for SOMETABLENAME, the first one it finds.

The use of the array came from this post. I have also read the linked post but to be honest I don't really understand it.

If there are other problems with my script (wrong grep etc), or some other better way of doing it, I'd appreciate the help.

EDIT:

table_list.txt is 2000 lines that looks like this

BI_CLAIMS_SUMMARY
BI_CLAIMS_SUMMARY_AUDIT
BI_MEDS_AUDIT
BI_MEDS_PATIENTS
BI_MEDS_SUMMARY

EDIT:

I have made the changes as suggested by Jessie below (thank you), but the output looks very much the same as before I tried to use my (wrong) version of the array.

table_name, file_name, full_path
BI_CLAIMS_SUMMARY, nohup.out, /sas/data/prod/EIP/depot/hiu/data_extract/tags/1.2/source/pl_sql/bi_claims_sum_plan_proc.sql
/sas/data/prod/EIP/depot/hiu/data_extract/tags/1.2/source/pl_sql/bi_claims_sum_proc.sql
/sas/data/prod/EIP/depot/hiu/sql_refresh/tags/1.0/source/10_load_claims_summary_audit_sqlserver.sas
/sas/data/prod/EIP/depot/hiu/sql_refresh/tags/1.0/resources/automation/nohup.out
BI_CLAIMS_SUMMARY_AUDIT, 10_load_claims_summary_audit_sqlserver.sas, /sas/data/prod/EIP/depot/hiu/data_extract/tags/1.2/source/pl_sql/bi_sum_claims_audit_proc.sql
/sas/data/prod/EIP/depot/hiu/data_extract/tags/1.3/source/pl_sql/bi_sum_claims_audit_proc.sql
/sas/data/prod/EIP/depot/hiu/data_extract/tags/1.4/source/pl_sql/bi_sum_claims_audit_proc.sql
/sas/data/prod/EIP/depot/hiu/meds/tags/1.0/source/HIU_RISK_REFRESH_CLAIMS_SUMMARY_AUDIT.sas
/sas/data/prod/EIP/depot/hiu/sql_refresh/tags/1.0/source/10_load_claims_summary_audit_sqlserver.sas

I'm expecting the BI_CLAIMS_SUMMARY to appear on each line. And also the filename nohup.out appears under the file_name, so it is not splitting the output of the grep correctly


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>