The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 09-22-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by aliahsan81 View Post
Hi ALL
I am greping some thing from a file,some thing is "/var/www/html" /var/www"/example" and so on its showing like this when u use echo.

Please use English in this forum. Write "you", not "u".
Quote:
i want to pass each one of them in a loop for processing.Like start with /var/www/html then 2nd and so one
But that not working any iead how i give one by one value.

What does "not working" mean? What does happen? What do you want to happen?
Quote:
My code

Please put code inside [CODE] tags.
Quote:
Code:
docroot=$(grep -H DocumentRoot /etc/httpd/conf.d/*.conf |
 awk -F' ' '{ print $3 }'| sort -u | uniq)

You don't need uniq; you have already removed duplicates with sort -u.

In fact, you don't need sort, either. It can be done with awk alone:

Code:
docroot=$(grep -H DocumentRoot /etc/httpd/conf.d/*.conf |
 awk -F' ' '!x[$3]++ { ++n } END { print n }'
Quote:
Code:
doccount=$(grep -H DocumentRoot /etc/httpd/conf.d/*.conf |
 awk -F' ' '{ print $3 }'| sort -u | uniq | wc -l)

for (( i=0; i <= $doccount; ++i ))

It is safer to stick to standard syntax:

Code:
i=0
while [ $i -le $doccount ]
do
   : whatever
   i=$(( $i + 1 ))
done
Quote:
Code:
 do
        confd="$docroot\n"
Code:
        confd="$docroot"
Quote:
Code:
echo $confd
        find $confd -type d -perm /o=w | while read DIR
do
do some thing 

done ## while done
done ##for done