find | gawk --- NOT WORKING


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find | gawk --- NOT WORKING
# 15  
Old 09-08-2008
code tags are like this.

[ code]
some text that will remain indented
[ /code]

(i puted some space after the [ cause i cant find a way to escape the tag itself :P)
about your script, i dont see the error....
# 16  
Old 09-08-2008
hi broli,

do i need a search Path ?

if i do, then how should i get the search path?

"All shell scripts should include a search path specification:

PATH=/usr/ucb:/usr/bin:/bin; export PATH

A PATH specification is recommended -- often times a script will fail for some people because they have a different or incomplete search path.

The Bourne Shell does not export environment variables to children unless explicitly instructed to do so by using the export command. "
# 17  
Old 09-09-2008
I don't think the PATH is the problem, the "done" error means something funny is in the file. You seem to be using DOS file names; are you using Cygwin? Is /usr/bin/bash the correct path to the Bash interpreter? Maybe try with /bin/sh there instead. Also try bash -vx new.sh and post the output here.

By the by, here is an equivalent script without the while loop:

Code:
find . -name '*.FMT' | xargs gawk -F '\t' '$2== "MS2" {print $1, $2}'

Note: you should have a space between "find ." and "-name '*.FMT'"

Last edited by era; 09-09-2008 at 04:47 AM.. Reason: Add xargs variant of script
# 18  
Old 09-09-2008
This is really weird, as I mentioned earlier, the find command doesn't have an output with tab separated fields.
I've asked several times to post the output of the find command and the desired output but I've give it up. Smilie
# 19  
Old 09-09-2008
Hi Era,


Thank you so much, the xargs did the job.No problemsSmilie

I am using cygwin. Can please help on how to check the correct path to the Bash interpreter?

Here is the output of "bash -vx new.sh"

$ bash -vx new.sh
#!/usr/bin/sh
find . -name '*.FMT' | while read line
do
gawk -F '\t' '$2== "MS2" {print $1, $2}' $line
done
new.sh: line 5: syntax error near unexpected token `done'
new.sh: line 5: `done'
# 20  
Old 09-09-2008
There maybe non-printing characters in your script. Highlight them by running your script through cat and post its output here that is...

Code:
cat -vet your_script

# 21  
Old 09-09-2008
This is out.


$ cat -vet new.sh
#!/bin/sh^M$
find . -name '*.FMT' | while read line^M$
do^M$
gawk -F '\t' '$2== "MS2" {print $1, $2}' $line^M$
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gawk program not working in a script

I've written a very simple gawk program which runs when I execute it at the POSIX shell but the corresponding '.awk' script I wrote doesn't return any data. I'm on an HP-UX running gawk version 3.1. (w/all the defaults) (As you can probably guess I'm a newbie going through the manual and trying... (2 Replies)
Discussion started by: RUCerius
2 Replies

2. Shell Programming and Scripting

Find && Gawk

I have several of the same file names(facts) in different directories that are "|" pipe delimited and are like such: xxx.xxx.xxx.xx1|blah|a|host|FQDN|domain||extra stuff blah1 blah2 host xxx.xxx.xxx.xx2|blah|a|host|FQDN|domain||extra stuff blah1 blah2 host... (2 Replies)
Discussion started by: metallica1973
2 Replies

3. Shell Programming and Scripting

Find not working right

if ] then leftarray=($(find . -type l -printf "%p\n" 2>/dev/null)) rightarray=($(find . -type l -printf "%l\n" 2>/dev/null)) for var in "${rightarray}" do maximumarray=`echo "$var" | tr -dc "/" | wc -c | tr -d " "` index=$(($index+1)) done ############# for numbers in... (3 Replies)
Discussion started by: xpukm
3 Replies

4. Shell Programming and Scripting

Gawk Find Pattern Print Lines Before and After

Using grep I can easily use: cvs log |grep -iB 10 -A 10 'date: 2013-10-30' to display search results and 10 lines before and after. How can this be accompished using gawk? (4 Replies)
Discussion started by: metallica1973
4 Replies

5. Shell Programming and Scripting

Working with FIND command

Hi , In /home/etc/files path ran the following command find . -name 'ABC*' | wc -l The output of the above command is 25 as expected In path /home path ran the following command find . -name '/home/etc/files/ABC*' | wc -l The output of the abvoe command is 0 . Why the above... (3 Replies)
Discussion started by: smile689
3 Replies

6. UNIX for Dummies Questions & Answers

Find with Prune not working

Hi I am trying to list all files in every subdirectory from a given location. However, I realise that 1 folder will have files that I am not interested in. This is using a .csh file to execute I have tried different scripts but to no avail. My current incarnation is below. Would someone be... (4 Replies)
Discussion started by: wonderbison
4 Replies

7. Shell Programming and Scripting

find command not working

Hi all, find command not working for me in a perticular directory.The same command is working fine in any other directory. Following is the command i issued: find . -type f -print my question is , is it possbile to disable a command only for a perticular directory ??...of course... (4 Replies)
Discussion started by: panyam
4 Replies

8. Shell Programming and Scripting

how to find in which shell i am working..

Hi Friends, I am new for this site.i have a small query.plz let me know the command to find in which shell presently i am working. (2 Replies)
Discussion started by: pineapple
2 Replies

9. Shell Programming and Scripting

How to find date Difference in AWK/GAWK with millisecond precision

Hi, I have a log file that has the date in this format "2006-05-30_13:14:04,256". I need to find the time difference between two log entries in milliseconds. How to achieve this in AWK/GAWK script? :confused: (2 Replies)
Discussion started by: omprasad
2 Replies

10. Shell Programming and Scripting

find/if statement not working

Hi guys: I am trying to delete multiple files in a folder with different names. Below is the script that I was trying, but it doesn't work ************************** #!/bin/ksh DATE=`date '+20%y%m%d'` DEL_DIR=<dir where files have to be deleted> let DATE2=$(($DATE - 2)) let DATE1=$(($DATE... (12 Replies)
Discussion started by: geomonap
12 Replies
Login or Register to Ask a Question