# Script

**URL:** <https://community.unix.com/t/script/150264>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [October 12, 2004, 7:45am UTC](https://community.unix.com/t/script/150264 "2004-10-12T07:45:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chambala5](https://community.unix.com/letter_avatar/chambala5/32/6_22734026db12803ebb3e059622ac3534.png) [@chambala5](https://community.unix.com/u/chambala5)\
**Post date:** [October 12, 2004, 7:45am UTC](https://community.unix.com/t/script/150264/1 "2004-10-12T07:45:38Z")

</div>

I am trying to get awk to search a file called $filetoDownload

check for matching files and place them in palocal\_check/dirs.txt

it will them cut out the first 10 fields and place them in

dirsfound.txt

The code as it looks now is as follows:#get the factset file  
filetoDownload=`echo $acct | awk -F',' '{print $1}'`

```
                    \#get the xls file to download
                    XlsfiletoDownload=\`echo $acct | awk -F',' '\{print $1\}'\`
                    
                    filetoDownload=\`echo $acct | awk -F',' '\{print $2\}'\`
                                                  filetoDownload=\`echo $filetoDownload | awk -F'_' '\{print $1"\_"$2"\_"$3"_"$4\}'\`

                                                
                                            
                    printLog "searching for $\{filetoDownload\}"  
                                            \#\#awk -F, '/'$filetoDownload'/ \{print $2\}' $palocal_check/dirs.txt &gt; $palocal_check/dirsfound.txt

                                                  \#\#cut -d "/" -f2-10 $palocal_check/dirs.txt &gt; $palocal_check/dirsfound.txt 

                                            awk -F, '/'$filetoDownload'/ \{print $1"/"$2"/"$3"/"$4"/"$5\}' $palocal_check/dirs.txt &gt; $palocal_check/dirsfound.txt

                                                 cat $palocal_check/dirsfound.txt
                                                       
            
                    DirectoryFound=\`cat $palocal_check/dirsfound.txt\`

                                                                                            
                    \#did we get a match
```

---

<div class="post-metadata">

**Author:** ![chambala5](https://community.unix.com/letter_avatar/chambala5/32/6_22734026db12803ebb3e059622ac3534.png) [@chambala5](https://community.unix.com/u/chambala5)\
**Post date:** [October 12, 2004, 11:46am UTC](https://community.unix.com/t/script/150264/2 "2004-10-12T11:46:00Z")

</div>

I would like to search a file called $filetodownload , print the first

five fields after the "/" , compare this file to another file called

$palocal\_check/dirsfound.txt and redirect the output of the

common files to $palocal\_check/dirsfound.txt

Is there any way of doing this in AWK ? or if not any other way

---

<div class="post-metadata">

**Author:** ![zazzybob](https://community.unix.com/user_avatar/community.unix.com/zazzybob/32/112_2.png) [@zazzybob](https://community.unix.com/u/zazzybob)\
**Post date:** [October 12, 2004, 11:53am UTC](https://community.unix.com/t/script/150264/3 "2004-10-12T11:53:41Z")

</div>

Posting the same question twice isn't going to get you a speedier response!

---

<div class="post-metadata">

**Author:** ![RTM](https://community.unix.com/user_avatar/community.unix.com/rtm/32/58_2.png) [@RTM](https://community.unix.com/u/RTM)\
**Post date:** [October 12, 2004, 12:11pm UTC](https://community.unix.com/t/script/150264/4 "2004-10-12T12:11:22Z")

</div>

Merged different threads. chambala5, use post reply instead of new thread button.

---

<div class="post-metadata">

**Author:** ![chambala5](https://community.unix.com/letter_avatar/chambala5/32/6_22734026db12803ebb3e059622ac3534.png) [@chambala5](https://community.unix.com/u/chambala5)\
**Post date:** [October 13, 2004, 4:47am UTC](https://community.unix.com/t/script/150264/5 "2004-10-13T04:47:48Z")

</div>

How do you compare two files in awk
