Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 21 Jul 2019, 21:41
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to use find with variable parameters? (Solved)
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [10 Posts]  
Author Message
arivas_2005

Joined: 25 Feb 2007
Posts: 210

PostPosted: Tue 04 Jul 2017, 16:32    Post subject:  How to use find with variable parameters? (Solved)  

greetings

i find and select file for extension.
i have the code

Code:
declare -a finales
finales[1]=".docx"
finales[2]=".sxw"
finales[3]=".sxc"
finales[4]=".odt"

for NUM  in {1..4}; do
   find /Z_SECCION/1 -maxdepth 1 -type f -name ${finales[$NUM]}
   #find /Z_SECCION/1 -maxdepth 1 -type f -name ${finales[NUM]}
   ## echo ${finales[$NUM]}
   # echo ${finales[NUM]}
done


not work
How to use find with variables as parameters

thanks!

Last edited by arivas_2005 on Wed 05 Jul 2017, 15:11; edited 1 time in total
Back to top
View user's profile Send private message 
arivas_2005

Joined: 25 Feb 2007
Posts: 210

PostPosted: Tue 04 Jul 2017, 16:48    Post subject:  

Excuse me ... the problem was the asterisko
Code:
finales[1]="*.docx"
finales[2]="*.sxw"
finales[3]="*.sxc"
finales[4]="*.odt"
for NUM  in {1..4}; do
   find /Z_SECCION/1 -maxdepth 1 -type f -name "${finales[$NUM]}"
done
 

Thank you again for your attention.
Back to top
View user's profile Send private message 
april

Joined: 14 Sep 2013
Posts: 1241
Location: Green Island baby!

PostPosted: Tue 04 Jul 2017, 17:16    Post subject:  

What does the directory structure look like that you are finding files in?
I'm seeing /Z_SECCION/1 is that correct?

I changed to "/TempSave/Scripts"
and got this error
Code:
# bash findvarious.sh
find: paths must precede expression: colour2.sh
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
find: `/TempSave/Scripts': No such file or directory
find: `/TempSave/Scripts': No such file or directory
find: `/TempSave/Scripts': No such file or directory

colour2.sh appears to be the first file found.
This was what my script looked like
Code:
#!/usr/bin/findvarious.sh

declare -a finales
finales[1]="*.sh"
finales[2]="*.sxw"
finales[3]="*.sxc"
finales[4]="*.odt"
#finales[1]=".docx"
#finales[2]=".sxw"
#finales[3]=".sxc"
#finales[4]=".odt"

for NUM  in {1..4}; do
   find /TempSave/Scripts/ -maxdepth 1 -type f   -name ${finales[$NUM]}
   #find /Z_SECCION/1 -maxdepth 1 -type f -name ${finales[NUM]}
   ## echo ${finales[$NUM]}
   # echo ${finales[NUM]}
done

#Excuse me ... the problem was the asterisko
#Code:   
#finales[1]="*.docx"
#finales[2]="*.sxw"
#finales[3]="*.sxc"
#finales[4]="*.odt"


#Thank you again for your attention.          arivas_2005
Back to top
View user's profile Send private message Yahoo Messenger 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1853
Location: Japan

PostPosted: Tue 04 Jul 2017, 23:09    Post subject:  

@arivas_2005: Please mark your thread as [solved] when you have found the solution to your problem.
It was not clear to me and probably not for april that you don't need any further help.

You seem to love arrays Laughing

If not using them is OK for you and if not even using find is OK you could simply use bash:
Code:
shopt -s nullglob
printf "%s\n" "/Z_SECCION/1/"{*.docx,*.sxw,*.sxc,*.odt}


Unless you have dozens of extensions to search for you could use find without a loop:
Code:
find "/Z_SECCION/1" -maxdepth 1 -name '*.docx' -o -name '*.sxw' -o -name '*.sxc' -o -name '*.odt'


...and if your version of find supports it you could use regex and make the code a bit shorter:
Code:
find "/Z_SECCION/1" -maxdepth 1 -regextype gnu-awk -regex ".*\.(docx|sxw|sxc|odt)$"


...and if it has to be a loop:
Code:
for ext in docx sxw sxc odt; do
   find "/Z_SECCION/1" -maxdepth 1 -name *.$ext
done


Buena suerte Wink
Back to top
View user's profile Send private message 
april

Joined: 14 Sep 2013
Posts: 1241
Location: Green Island baby!

PostPosted: Wed 05 Jul 2017, 04:29    Post subject:  

I am fully aware he has solved it but the subject interests me including your post which somewhat blows me away. Scripting capabilities are just mindblowing. Much food for thought.
Back to top
View user's profile Send private message Yahoo Messenger 
musher0

Joined: 04 Jan 2009
Posts: 14233
Location: Gatineau (Qc), Canada

PostPosted: Wed 05 Jul 2017, 11:48    Post subject:  

Very interesting discussion.
_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
arivas_2005

Joined: 25 Feb 2007
Posts: 210

PostPosted: Sun 16 Jun 2019, 10:50    Post subject:    

regards
here again Confused
excuseme for opening this thread again Embarassed
but I have the same problem
and I can not find you out

the scriptillo is
Code:
#!/bin/bash
 comand0=$(Xdialog --title "Preparando los detalles de limpieza en Z_SECCION" \
      --stdout --separator "~" --inputbox "$MENSAJE""Intro command grep with params values Ej: grep -v -i "tre\|fou"" 12 110 "grep")
  cd /Z_SECCION/1
    OLDIFS=$IFS ; IFS=$'\n'
        # line command work fine  ---------------------------
      #for i in $(find ./ -type d ! -iname '*--*' | grep -i -v 'tre\|fou' | sed 's/..//'); do rm -rf $i ; done
      # but, grep in variable comand0 not work  -----------
      for i in $(find ./ -type d ! -iname '*--*' | $comand0 | sed 's/..//'); do rm -rf --no-preserve-root $i ; done
   IFS=$OLDIFS


I want to mix grep with find but passing grep in variable
ex: grep -v -i "tre\|fou"
Online command works perfect, but
when entering it in variable gives the error:
: line 8: grep -i -v 'tre\|fou': command not found grep -v -i "tre\|fou"
what will be the trick to make it work
again thanks for the support
Back to top
View user's profile Send private message 
arivas_2005

Joined: 25 Feb 2007
Posts: 210

PostPosted: Sun 16 Jun 2019, 22:15    Post subject:  

eureka! Very Happy

after insistent 7 hours of trial and error.
I found the arrangement.
Thank you for the opportunity
Here I leave my scriptillo that works.

Code:
#!/bin/bash
 cd /Z_SECCION/1
  CONDITION=`Xdialog --stdout --inputbox "parametro para find " 8 125 ""`
#   # funciona con CADENA y eval-------------------------------------------
 TMP=$IFS; IFS=$'\n'
  CADENA="find ./ -type d ! -iname '*--*' | "$CONDITION" | sed 's/..//'"
  for i in $(eval $CADENA); do rm -rf $i ; done
  IFS=$TMP 
# grep -i -v "tre\|cua"  for Xdialog

these lines are the solution
CADENA="find ./ -type d ! -iname '*--*' | "$CONDITION" | sed 's/..//'"
$(eval $CADENA)

I spent my Sunday Embarassed
greetings for all!
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1853
Location: Japan

PostPosted: Sun 16 Jun 2019, 22:58    Post subject:  

arivas_2005 wrote:
regards
here again Confused
excuseme for opening this thread again Embarassed
but I have the same problem

This thread has nothing to do with your problem.

Indeed you already described the same problem, but in a different thread. The answer you received should give you a clue why you receive an error and how to avoid it.

Edit: I somehow didn't notice your last post. Anyway, it seems you could have saved some hours by learning from your own threads Laughing .
Back to top
View user's profile Send private message 
arivas_2005

Joined: 25 Feb 2007
Posts: 210

PostPosted: Mon 17 Jun 2019, 10:07    Post subject:  

my greeting @MochiMoppel
effectively. the key was in the thread:
http://www.murga-linux.com/puppy/viewtopic.php?t=110667
In a moment of lucidity, From there I re-took the idea.
but, while there is confusion, the path is not found.
thanks for your comments Very Happy
and thank you for the support you offer in this medium
successes!
arivas
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [10 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0493s ][ Queries: 12 (0.0066s) ][ GZIP on ]