how to get only .json file names in string array to iterate over filename

how to get only .json file names in string array to iterate over filename

Problem: I have 12 .json files at path /side/containers_automation/sc/2021-05/ This path can have different file extensions as well.

find /side/containers_automation/sc/2021-05 -type f -name "*.json"

/side/containers_automation/sc/2021-05/ci-userstory-tlm.json
/side/containers_automation/sc/2021-05/ci-userstory-spe.json
/side/containers_automation/sc/2021-05/ci-e2e-tlm.json
/side/containers_automation/sc/2021-05/ci-userstory-dm-inbound.json
/side/containers_automation/sc/2021-05/cucumber-ci-e2e-ta-dm.json
/side/containers_automation/sc/2021-05/cucumber-ci-e2e-tlm.json
/side/containers_automation/sc/2021-05/bvt-dm.json
/side/containers_automation/sc/2021-05/ci-userstory-dm-outbound-execution.json
/side/containers_automation/sc/2021-05/ci-e2e-dm.json
/side/containers_automation/sc/2021-05/cucumber-ci-userstory-tlm.json
/side/containers_automation/sc/2021-05/ci-userstory-dm-outbound.json
/side/containers_automation/sc/2021-05/uat-dm.json

want to copy just filenames of type .json and append a keyword (ex: automation) before these. ex: automation-ci-userstory-tlm automation-cucumber-ci-e2e-ta-dm automation-uat-dm etc. and store these names in a string array so that i can iterate over this.

I am new to shell scripting. Would need your help on this. Thank you. My thought ->

  1. Get file names by command

    (find /side/containers_automation/sc/2021-05 -type f -name "*.json" > conf_search)

  2. trim initial path (

    /side/containers_automation/sc/2021-05) and file format (.json)

/side/containers_automation/sc/2021-05/uat-dm.json 3. just get uat , ci-userstory-tlm, ci-userstory-tlm , put this in string array 4. iterate over this I know it is complex and lengthy solution.



Read more here: https://stackoverflow.com/questions/67927942/how-to-get-only-json-file-names-in-string-array-to-iterate-over-filename

Content Attribution

This content was originally published by saurabh kumar at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: