ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt"
# 8  
Old 04-17-2008
well... your original version would have had the same issue. This is a limitation of this approach to begin with.
Try or ghostdog74's post above:
Code:
find /Users/mirko/Unix -type f -name '*.txt'

# 9  
Old 04-17-2008
Quote:
Originally Posted by vgersh99
well... your original version would have had the same issue. This is a limitation of this approach to begin with.
Try or ghostdog74's post above:
Code:
find /Users/mirko/Unix -type f -name '*.txt'

I had already tryed, but:
It works using it "stand-alone", for example:
MacBook-di-Mirko:unix mirko$ find /Users/mirko/Unix -type f -name '*.txt'
/Users/mirko/Unix/file.txt
/Users/mirko/Unix/lettera.txt
/Users/mirko/Unix/motion/README.txt
/Users/mirko/Unix/Radio Ga Ga.txt
/Users/mirko/Unix/Save Me.txt
/Users/mirko/Unix/Seven Seas Of Rhye.txt

It doesn't work using it in a for, for example:
MacBook-di-Mirko:unix mirko$ ./test.sh
/Users/mirko/Unix/file.txt
/Users/mirko/Unix/lettera.txt
/Users/mirko/Unix/motion/README.txt
/Users/mirko/Unix/Radio
Ga
Ga.txt

/Users/mirko/Unix/Save
Me.txt
/Users/mirko/Unix/Seven
Seas
Of
Rhye.txt


It split the file names with one or more spaces in their names

PS: the script is:
Code:
#!/bin/sh

for file in `find /Users/mirko/Unix -type f -name '*.txt'`
do
	echo ${file}
done

# 10  
Old 04-17-2008
that's why now

find . -type f | grep txt$ | while read line; do echo "${line}";cat "${line}"; done
# 11  
Old 04-17-2008
Code:
#!/bin/sh

find /Users/mirko/Unix -type f -name '*.txt' | while read file
do
	echo "[${file}]"
done

# 12  
Old 04-17-2008
There's more than one way to skin a cat Smilie
# 13  
Old 04-17-2008
Quote:
Originally Posted by DNAx86
MacBook-di-Mirko:unix mirko$ ./test.sh
/Users/mirko/Unix/file.txt
/Users/mirko/Unix/lettera.txt
/Users/mirko/Unix/motion/README.txt
/Users/mirko/Unix/Radio
Ga
Ga.txt

/Users/mirko/Unix/Save
Me.txt
/Users/mirko/Unix/Seven
Seas
Of
Rhye.txt


It split the file names with one or more spaces in their names

PS: the script is:
Code:
#!/bin/sh

for file in `find /Users/mirko/Unix -type f -name '*.txt'`
do
	echo ${file}
done

As ever, you need to put your variables in double quotes. Just get in the habit of doing that always and you will avoid a lot of surprises.

Code:
for file in `find /Users/mirko/Unix -type f -name '*.txt'`
do
	echo "${file}"
done

However, the "for" will also split on whitespace, so you need to do that differently, too.

Code:
find /Users/mirko/Unix -type f -name '*.txt' |
while read file; do
  echo "$file"
done

Or, you can fidget with the value of $IFS to make space not be a token separator, but that's not something I particularly recommend.

(There are still some pitfalls. If you had files with backslashes in their names, those would be tricky even with this code.)
# 14  
Old 04-18-2008
Quote:
Originally Posted by DNAx86
I had already tryed, but:
It works using it "stand-alone", for example:
MacBook-di-Mirko:unix mirko$ find /Users/mirko/Unix -type f -name '*.txt'
/Users/mirko/Unix/file.txt
/Users/mirko/Unix/lettera.txt
/Users/mirko/Unix/motion/README.txt
/Users/mirko/Unix/Radio Ga Ga.txt
/Users/mirko/Unix/Save Me.txt
/Users/mirko/Unix/Seven Seas Of Rhye.txt

It doesn't work using it in a for, for example:
MacBook-di-Mirko:unix mirko$ ./test.sh
/Users/mirko/Unix/file.txt
/Users/mirko/Unix/lettera.txt
/Users/mirko/Unix/motion/README.txt
/Users/mirko/Unix/Radio
Ga
Ga.txt

/Users/mirko/Unix/Save
Me.txt
/Users/mirko/Unix/Seven
Seas
Of
Rhye.txt


It split the file names with one or more spaces in their names

PS: the script is:
Code:
#!/bin/sh

for file in `find /Users/mirko/Unix -type f -name '*.txt'`
do
	echo ${file}
done

what do you want to do with those *.txt files it finds?? I believe you don't just want to echo their names out. If that's the case, no need for a for loop/while loop because the find command displays to stdout. Otherwise, you can use -exec or xargs for simple task, or coupled with while loop for more complicated tasks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Cmd="grep 'Name:' |awk -F' ' '{print $2}'"

Hi Is it possible to get the below code working.? cmd="grep 'Name:' |awk -F' ' '{print $2}'|xargs -i basename {}" echo $cmd ( rman target / <<EOF1 LIST COPY ; exit EOF1 ) | `$cmd` in nutshell I want to be able to preset cmd as depending on script flow it can be... (2 Replies)
Discussion started by: zam
2 Replies

3. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

6. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

7. Shell Programming and Scripting

grep '\~' b | awk '{print $1","$3}' | sed -e 's/~//g'

Hi all, grep '\~' b | awk '{print $1","$3}' | sed -e 's/~//g' Iam using above command for some report... can this be done using any one of them either sed or awk or grep... (3 Replies)
Discussion started by: harshakusam
3 Replies

8. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

10. Shell Programming and Scripting

grep to find content in between curly braces, "{" and "},"

problem String ~~~~~~~~~~~~~~~~~~ icecream= { smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" } aend = {smart vc4 eatr kalu} output needed ~~~~~~~~~~~~~~~~~~ smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" smart vc4... (4 Replies)
Discussion started by: keshav_rk
4 Replies
Login or Register to Ask a Question