Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

substitute string

Status
Not open for further replies.

krava

Programmer
Jun 4, 2007
48
YU
hi,

i would like to substitute a substring with the given string in filanames. I wrote this script that use awk:

Code:
function subFlNmPart(){
for i in `find -name "$1" -print`; do
  bn="$(basename $i)";
  #eval o=\"$( awk -v inFl=$bn -v target=$2 -v word=$3 'BEGIN{
      sub(target, word, inFl); 
      print inFl}' )\";
  o=`awk -v inFl=$bn -v target=$2 -v word=$3 'BEGIN{
      sub(target, word, inFl); 
      print inFl }'`;
  echo $o;
done
}

USAGE: subFlNmPart "file*more*csv" "more" "all"
OUTPUT: file1_more.csv -> file1_all.csv for example


I am not sure why $o is not assigned. Any ideas?


k.
 
What is the output you are actually getting?

find needs at least one parameter before -name, i.e. the path to search.

If you are commenting out the eval statement, you need to comment out all three lines including the awk script.

On some platforms awk does not work with only a BEGIN clause, you may need to echo | awk 'BEGIN { ... }'.

Annihilannic.
 
thanks

o=`echo | awk 'BEGIN { ... }'` works fine in this context

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top