Sponsored Content
Full Discussion: for loop and grep question
Top Forums Shell Programming and Scripting for loop and grep question Post 302309781 by redalert013 on Wednesday 22nd of April 2009 10:30:45 PM
Old 04-22-2009
Error 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.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep in a loop

Hi , I am trying a script which takes user input userid . I am stuck how to check whether that is a valid user id or not in the audit log files. My code is : cd $CCP_AUDIT cat * > /export/home/$USR/l***/files echo "UserId:\c" read UserId #Date Function echo "DATE : \c" read xxx I... (7 Replies)
Discussion started by: gundu
7 Replies

2. UNIX for Dummies Questions & Answers

grep -v while loop

alist contain: a b c d e blist contain: a b c the code: #!/usr/bin/ksh cat blist | while read line do grep -V "$line" alist > data done (8 Replies)
Discussion started by: bobo
8 Replies

3. Shell Programming and Scripting

Grep commands in loop

Hi All, Reference to my previous post I need to compare all the lines in the file1 with file2 for this condition if file1 {$3,$5} ==file2 {$3,$5} then grep file2{$1}latest date. need output in file3 10/04/2008 09/04/2008 09/04/2008 08/04/2008 can anyone suggest me Thanks... (0 Replies)
Discussion started by: karthikn7974
0 Replies

4. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

5. Shell Programming and Scripting

Using grep within a while loop

Hi all, I have the below script to get input but i cannot get grep to work. input1.txt AAAAAAAAG input2.txt >gi|184009.1| LEAFY-like |AAAAAAAAGSGGGDHLPY However, when i use grep -f input1.txt input2.txt i cannot get any output matches (note that the match is underlined). Is it... (8 Replies)
Discussion started by: turkishvan
8 Replies

6. Shell Programming and Scripting

Help on grep in a do while loop

So this is what I'm trying to do: I have a file called registry.txt which has a list of registry entries I want to search for. I have another file called inctrl.txt on which I want to perform the search on. Here's the example contents of registry.txt SOFTWARE\Microsoft\Security... (3 Replies)
Discussion started by: r4v3n
3 Replies

7. Red Hat

using grep in a while loop

Hello everybody, I have been searching it, but it seems I am unable to find the correct information, that s why I am asking you guys, hoping somebody get an idea. Here is my problem : I want a script to loop until a string is identified in a log file. Here is the script : #!/bin/sh... (5 Replies)
Discussion started by: guyiom
5 Replies

8. Homework & Coursework Questions

GREP loop

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I need to search through the users home directories for keywords, display them. The code listed below will show... (7 Replies)
Discussion started by: jcllns1
7 Replies

9. Shell Programming and Scripting

Grep issue in for loop

Hi friends, I am trying to use a grep command in for loop but i keep getting an error message on the grep, here is the code grep -i "Target connection group" $LogName | awk '{print $10}' > TableNames.rpt cat TableNames.rpt | sort -u > DistinctTable.rpt ... (3 Replies)
Discussion started by: Aditya_001
3 Replies

10. Shell Programming and Scripting

Ps ax with grep in loop

Hello, I have built the following script to check if processes supplied by the argument are running or not. #!/bin/bash PROCLIST=$1 PROCESS="0" ERROR_PROCS="" IFS='+' read -ra ADDR <<< "$PROCLIST" for PROC in "${ADDR}"; do if ; then PROCESS=1 ... (9 Replies)
Discussion started by: nms
9 Replies
break(1)							   User Commands							  break(1)

NAME
break, continue - shell built-in functions to escape from or advance within a controlling while, for, foreach, or until loop SYNOPSIS
sh break [n] continue [n] csh break continue ksh *break [n] *continue [n] ksh93 +break [n] +continue [n] DESCRIPTION
sh The break utility exits from the enclosing for or while loop, if any. If n is specified, break n levels. The continue utility resumes the next iteration of the enclosing for or while loop. If n is specified, resume at the n-th enclosing loop. csh The break utility resumes execution after the end of the nearest enclosing foreach or while loop. The remaining commands on the current line are executed. This allows multilevel breaks to be written as a list of break commands, all on one line. The continue utility continues execution of the next iteration of the nearest enclosing while or foreach loop. ksh The break utility exits from the enclosed for, while, until, or select loop, if any. If n is specified, then break n levels. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be exited. The continue utility resumes the next iteration of the enclosed for, while, until, or select loop. If n is specified then resume at the n- th enclosed loop. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be used. On this manual page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words that follow a command preceded by ** that are in the format of a variable assignment are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign, and also that word splitting and file name generation are not performed. ksh93 break is a shell special built-in that exits the smallest enclosing for, select, while, or until loop. It also exits the nth enclosing loop if n is specified. Execution continues at the command following the loop or loops. If n is specified, it must be a positive integer >=1. If n is larger than the number of enclosing loops, the last enclosing loop is exited. continue is a shell special built-in that continues execution at the top of the smallest enclosing for, select, while, or until loop, if any; or of the top of the nth enclosing loop if n is specified. If n is specified, it must be a positive integer >=1. If n is larger than the number of enclosing loops, the last enclosing loop is used. On this manual page, ksh93(1) commands that are preceded by one or two + symbols are special built-in commands and are treated the follow- ing ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Built-in commands are not valid function names. 5. Words following a command preceded by ++ that are in the format of a variable assignment are expanded with rules as a variable assignment. This means that tilde substitution is performed after the = sign and field splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), exit(1), ksh(1), ksh93(1), sh(1), attributes(5) SunOS 5.11 8 Apr 2008 break(1)
All times are GMT -4. The time now is 04:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy