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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep Different Files Using a Loop? foleyml Shell Programming and Scripting 6 01-02-2009 01:41 AM
grep and loop files kashik Shell Programming and Scripting 4 06-16-2008 08:41 AM
Grep commands in loop karthikn7974 Shell Programming and Scripting 0 04-28-2008 09:16 AM
grep -v while loop bobo UNIX for Dummies Questions & Answers 8 01-26-2007 10:53 PM
grep in a loop gundu Shell Programming and Scripting 7 03-28-2005 04:59 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-22-2009
redalert013 redalert013 is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 1
Exclamation for loop and grep question

I am trying to work on a script file for tcsh but am fairly new to linux and have several questions.

1. What is the most effective way to set up a type of for loop? I need to run two loops that will each run in steps from a starting value to final value, eg i=0, 1==10, i++ in any other language. What is the most efficient way to set this up?

So far we came up with:
set i_forloopval = `echo "forloop" | awk '{for(p=0.7;p<1.43;p=p+0.08){print p}}'`
set j_forloopval = `echo "forloop" | awk '{for(p=0.9;p<1.81;p=p+0.1){print p}}'`

foreach i ($i_forloopval)
foreach j ($j_forloopval)

but it seems like there must be a more efficient way to go about this.

2. Every time it runs through the loop, it is going to run a program that creates a unique output file. Instead of having to manually search through this file, I was hoping to use grep to search for the line that we need.

A given output might look like:
1\1\GINC-NODE006\Freq\RB3LYP\6-311G(d)\Br2\TYLERT\02-Feb-2009\0\\#N Ge
om=AllCheck Guess=Read SCRF=Check GenChk RB3LYP/6-311G(d) Freq\\Title\
\0,1\Br,0.,0.,-0.0263112705\Br,0.,0.,2.3073112705\\Version=AM64L-G03Re
vD.01\State=1-SGG\HF=-5148.2839416\RMSD=5.854e-11\RMSF=1.293e-06\Therm
al=0.0034749\Dipole=0.,0.,0.\DipoleDeriv=0.,0.,0.,0.,0.,0.,0.,0.,0.,0.
,0.,0.,0.,0.,0.,0.,0.,0.\Polar=17.7366557,0.,17.7366557,0.,0.,51.89093
66\PG=D*H [C*(Br1.Br1)]\NImag=0\\0.00021679,0.,0.00021679,0.,0.,0.1438
2273,-0.00021679,0.,0.,0.00021679,0.,-0.00021679,0.,0.,0.00021679,0.,0
.,-0.14382273,0.,0.,0.14382273\\0.,0.,0.00000224,0.,0.,-0.00000224\\\@

the only information that is needed out of this is HF=-5148.2839416. What is the best way to extract only this from the output file? This is further complicated by the fact that this does not always occur on one line but will sometimes appear as:
one one line: HF=-5148.28
39416 and then this part will be wrapped on to the next line.

Any help would be appreciated.
  #2 (permalink)  
Old 04-23-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
Quote:
Originally Posted by redalert013 View Post
I am trying to work on a script file for tcsh but am fairly new to linux and have several questions.

1. What is the most effective way to set up a type of for loop? I need to run two loops that will each run in steps from a starting value to final value, eg i=0, 1==10, i++ in any other language. What is the most efficient way to set this up?

So far we came up with:
set i_forloopval = `echo "forloop" | awk '{for(p=0.7;p<1.43;p=p+0.08){print p}}'`
set j_forloopval = `echo "forloop" | awk '{for(p=0.9;p<1.81;p=p+0.1){print p}}'`

foreach i ($i_forloopval)
foreach j ($j_forloopval)

but it seems like there must be a more efficient way to go about this.

2. Every time it runs through the loop, it is going to run a program that creates a unique output file. Instead of having to manually search through this file, I was hoping to use grep to search for the line that we need.

A given output might look like:
1\1\GINC-NODE006\Freq\RB3LYP\6-311G(d)\Br2\TYLERT\02-Feb-2009\0\\#N Ge
om=AllCheck Guess=Read SCRF=Check GenChk RB3LYP/6-311G(d) Freq\\Title\
\0,1\Br,0.,0.,-0.0263112705\Br,0.,0.,2.3073112705\\Version=AM64L-G03Re
vD.01\State=1-SGG\HF=-5148.2839416\RMSD=5.854e-11\RMSF=1.293e-06\Therm
al=0.0034749\Dipole=0.,0.,0.\DipoleDeriv=0.,0.,0.,0.,0.,0.,0.,0.,0.,0.
,0.,0.,0.,0.,0.,0.,0.,0.\Polar=17.7366557,0.,17.7366557,0.,0.,51.89093
66\PG=D*H [C*(Br1.Br1)]\NImag=0\\0.00021679,0.,0.00021679,0.,0.,0.1438
2273,-0.00021679,0.,0.,0.00021679,0.,-0.00021679,0.,0.,0.00021679,0.,0
.,-0.14382273,0.,0.,0.14382273\\0.,0.,0.00000224,0.,0.,-0.00000224\\\@

the only information that is needed out of this is HF=-5148.2839416. What is the best way to extract only this from the output file? This is further complicated by the fact that this does not always occur on one line but will sometimes appear as:
one one line: HF=-5148.28
39416 and then this part will be wrapped on to the next line.

Any help would be appreciated.
I am not quite clear about your first question. please elaborate on what you are trying to implement.

for the second question, please try this

awk -F "\\" '{for(i=1;i<=NF;i++){if ($i ~ /HF/)print $i}}' file


cheers,
Devaraj Takhellambam
Sponsored Links
Closed Thread

Bookmarks

Tags
foreach, grep, loops, replace, search

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0