Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep within a batch file 2

Status
Not open for further replies.

ddrillich

Technical User
Jun 11, 2003
546
US
Good Day,

I have a batch file tst.sh which has a thousand or so lines as such -

grep -i DJResultListSEO /opt/autonomy/DAH/logs/query.log.29-Oct-10-00.01.07
grep -i DJResultListSEO /opt/autonomy/DAH/logs/query.log.29-Oct-10-00.02.07
grep -i DJResultListSEO /opt/autonomy/DAH/logs/query.log.29-Oct-10-00.03.14
grep -i DJResultListSEO /opt/autonomy/DAH/logs/query.log.29-Oct-10-00.04.25
grep -i DJResultListSEO /opt/autonomy/DAH/logs/query.log.29-Oct-10-00.05.33

When running ./tst.sh, I get the following error messages -

: No such file or directorys/query.log.29-Oct-10-23.53.50
: No such file or directorys/query.log.29-Oct-10-23.55.11
: No such file or directorys/query.log.29-Oct-10-23.57.00
: No such file or directorys/query.log.29-Oct-10-23.59.00

When I run each command from the command prompt I have no issue.

What am I missing?

Regards,
Dan

 
Hi

ddrillich said:
: No such file or directorys/query.log.29-Oct-10-23.53.50
That error message says everything.

Normally the error message should look like this :
Code:
[blue]master #[/blue] grep -i DJResultListSEO  /opt/autonomy/DAH/logs/query.log.29-Oct-10-00.01.07
grep: /opt/autonomy/DAH/logs/query.log.29-Oct-10-00.01.07: No such file or directory
But apparently the message was "folded" abit :
[tt]
[red]grep: /opt/autonomy/DAH/logs/query.log.29-Oct-10-00.01.07[/red]
[green]: No such file or directory[/green][red]\ /[/red]
[green]\____________ ____________/[/green] [red]\_____________ ____________/[/red]
[green]|[/green] + [red]|[/red]
[green]V[/green] [red]V[/red]
[green]: No such file or directory[/green][red]s/query.log.29-Oct-10-00.01.07[/red]
[/tt]
I hope you see the problem now : there is a [tt]\n[/tt] ( carriage return ) character at the end of lines.

Remove them with [tt]dos2unix[/tt] or with [tt]sed -i 's/\r$//' /input/file[/tt] .


Feherke.
 
Good Day,

Thank you both. Let me show you please the console, that shows that running it from the prompt works well and it fails from within the script -

Code:
[autonomy@sbkj2ksrchdahp01 dan]$ ./tst2.sh
: No such file or directorys/query.log.29-Oct-10-00.01.07
: No such file or directorys/query.log.29-Oct-10-23.59.00
[autonomy@sbkj2ksrchdahp01 dan]$
[autonomy@sbkj2ksrchdahp01 dan]$
[autonomy@sbkj2ksrchdahp01 dan]$
[autonomy@sbkj2ksrchdahp01 dan]$
[autonomy@sbkj2ksrchdahp01 dan]$ cat tst2.sh
grep -i DJResultListSEO  /opt/autonomy/DAH/logs/query.log.29-Oct-10-00.01.07
grep -i DJResultListSEO  /opt/autonomy/DAH/logs/query.log.29-Oct-10-23.59.00
[autonomy@sbkj2ksrchdahp01 dan]$ ./tst2.sh
: No such file or directorys/query.log.29-Oct-10-00.01.07
: No such file or directorys/query.log.29-Oct-10-23.59.00
[autonomy@sbkj2ksrchdahp01 dan]$ grep -i DJResultListSEO  /opt/autonomy/DAH/logs/query.log.29-Oct-10-00.01.07
29/10/2010 00:00:17 [12] Always: /action=query&mindate=1288238400e&print=fields&totalresults=true&sort=Date&databasematch=wsjie_90DAYS&maxresults=5000000&printfields=DREREFERENCE DRETITLE DREDATE spellingquery copyright display_name type level section page publication date article_doc_date print_page orig_obj_ref targeturl id guid credit DREDJDBNAME code_attr company statistic summary summary_body summary_r summary_main_hed headline main_hed byline qsummary indexletter category topicid topicName topicInitials seoname product DRECONTENT PARENT_CATEGORY KEYWORDS DESCRIPTION THUMBNAILURL IMAGENAME PI_KEYWORD SEO_SUMMARY_MAIN_HED&template=DJResultListSEO&text=* (10.240.81.248)
....

[autonomy@sbkj2ksrchdahp01 dan]$

Regards,
Dan
 
Hi

Feherke said:
I hope you see the problem now : there is a [tt]\n[/tt] ( carriage return ) character at the end of lines.
Oops, a typo. That should be "[red][tt]\r[/tt][/red]" ( carriage return )". But at least I wrote the character's name correctly.

Feherke.
 
Actually, even the very straight forward tst3.sh fails -

[autonomy@sbkj2ksrchdahp01 logs]$ cat tst3.sh
cd /opt/autonomy/DAH/logs
ls
[autonomy@sbkj2ksrchdahp01 logs]$ ./tst3.sh
: No such file or directory/autonomy/DAH/logs
: command not foundls

Regards,
Dan
 
Not sure I got it feherke. So, what do you think is wrong with the following script on this particular server (as it works on another one)? -

Code:
[autonomy@sbkj2ksrchdahp01 logs]$ cat tst3.sh
cd /opt/autonomy/DAH/logs
ls

Regards,
Dan
 
Can I ask how did you create you shell script? You mentioned the word batch file in the beginning, therefore I am wondering if you created this file on a Windows machine and copied to a linux box. This would have extraneous characters like the other folks have mentioned which is what might be generating your errors.
 
feherke is right. I'd bet cash on it. A star for feherke.

Try this to fix it...
Code:
dos2unix tst.sh
./tst.sh
 
Thank you all. I actually created the script with vi. Let me check the dos2unix idea when I have access to this server...

Regards,
Dan
 
Good Day,

Let me take back what I said earlier; the original script _was_ taken to MSDOS for some formatting. Sorry about that.

Regards,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top