I'm trying to create a script that can:look for a file containing foobar as name a script is executed on this file and the output must be stored in a new CSV file, which is created automatically and which has the same name as the searched file. The only difference is that the extension is changed to CSV.This is my script. :#!/bin/bash# search for file containing foobar as a name in the directoryfor file in /home/user/Documents/* ;do if [[ $file == *$foobar* ]]; thentouch  /home/user/Documents/collectCSV/csv1.csv# executing script of modelising foobar file ==> extract some data from $foobar file and insert it in the# created file csv1.csv/home/user/scriptModelise.pl  $file >> /home/user/Documents/collectCSV/csv1.csvelse echo foobar file not found fidoneThe problem is that this method of creating a file is static. I didn't succeed in making the file creation automatic. I mean when it finds a foobar file it will be modelised in a new file that will be created.Any help please ?
how to create a file automatically?
bash;shell script;touch
tryfor file in *$foobar*do   dest=$(echo $file| sed -e 's/\(.*\)\.[^\.]*$/\1.csv/' )   if test -f $file    then        /home/user/scriptModelise.pl  $file >> /home/user/Documents/collectCSV/$dest   else     echo no $foobar file   fidonewhere\(.*\)\.[^\.]*$ capture a pattern with any char, (end of pattern) followed by a dot, non dot till end of line\1.csv insert pattern found, add .csv*$foobar* will expand to litteral *foobar* (with proper value) if no matching file are found. hence the need for test -f $file Edit:\(.*\)\.[^\.]*$  (left hand side: finding pattern(s) )split into ( _ are place holder )__.*__________ a pattern with any char (dot has a special meaning: any char)__.*__\._______  a pattern with any char, followed by a dot (escaped dot is a plain dot)__.*__\.[^\.]*$ pattern with any char, (end of pattern) followed by a dot, non dot ([^\.]*) till end of line (dollar sign is special for end of line)\(__\)__________ capture the first part of pattern.\1.csv (right hand side, what to do)\1____ \1 match what was within first \( \) , \2 for second and so on, use & for whole pattern.