09-24-2002
Yes it works. I actually stumbled upon this a few months ago.
I once pondered why this was. I get the same output whether I use > or >> to write out the file if it is outside the loop.
I believe that it is because the "> file.3" is outside of the loop so
ALL of the grepped data goes out together and is written ONCE and not each time the loop runs.
I believe that this is a little faster than writing each time the loop finishes, especially with 2 large files. I only had about 200 lines for file1, but file.2 had almost 1000 lines to be searched.
You would be right if I had put the > file.3 inside the loop, it would overwrite the file each time instead of appending as with >> file.3 would do.
So both of these are the same.
_________________________
for name in `cat file.1 `
do
grep $name file.2
done > file.3
_________________________
for name in `cat file.1 `
do
grep $name file.2 >> file.3
done
_________________________
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I am new to unix shell programming.
I want to write a shell script for a functionality existing in mainframe system.
I have one file as below as input
123456
&__987
&12yuq
abcdef
_ referes to blank
condition:whenever the input file is having &__ ,it should be replaced... (4 Replies)
Discussion started by: charan0703
4 Replies
2. Shell Programming and Scripting
Hi All, I need to grep few files which has words like the below in the file name , which i want to put it in a file and and grep for the files which contain these names and move it to a new directory ,
full file name -C20091210.1000-20091210.1100_SMGBSC3:1000... (2 Replies)
Discussion started by: anita07
2 Replies
3. Shell Programming and Scripting
Hello,
I have File1 in a directory A, a File2 in a directory B.
If the File2 is not empty
Then I have to move File1 from directory A to a directory archive
Else no action.
Is it possible to do this from one command line?
Thank you in advance for your answers.
Madi (2 Replies)
Discussion started by: AngelMady
2 Replies
4. UNIX for Dummies Questions & Answers
Hi All,
I have a large text file which is a combination of multiple files. This is what I used and it worked.
for i in /home/docs/text/*
do
cat $i >> Single_File
done
Now wondering, if there is a way to sort that single large file based on timestamps in ascending order. Text file... (11 Replies)
Discussion started by: prrampalli
11 Replies
5. Shell Programming and Scripting
I have a file in which the data is stored in pairs of lines. The first line (beginining with ">") is a header, the second line is a sequence.
I would like to sort the file by species name. Desired output for the example file:
I can use
sort -t'_' -k2
to alphabetize headers in the... (1 Reply)
Discussion started by: pathunkathunk
1 Replies
6. Shell Programming and Scripting
Dear Friends,
I am looking for a shell script to merge input files into one file .. here is my idea:
1st paramter would be outfile file (all input files content)
read all input files and merge them to input param 1
ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies
7. Shell Programming and Scripting
Hi
I need to order these lines from a txt file my file looks like this
IMSI ........................ 1234567890
APN ......................... INTERNET.COM
APN ......................... MMS.COM
APN ......................... WAP.COM
APN ......................... BA.COM
IMSI... (4 Replies)
Discussion started by: alone77
4 Replies
8. Shell Programming and Scripting
In the below bash a file is downloaded when the program is opened and then that file is searched based on user input and the result is written to a new file.
For example, the bash is opened and the download.txt is downloaded, the user then enters the id (NA04520). The id is used to search... (5 Replies)
Discussion started by: cmccabe
5 Replies
9. Shell Programming and Scripting
Hi All,
I have one file containing thousands of table names in single column. Now I want that file split into multiple files e.g one file containing table names starting from A, other containing all tables starting from B...and so on..till Z.
I tried below but it did not work.
for i in... (6 Replies)
Discussion started by: shekhar_4_u
6 Replies
10. Shell Programming and Scripting
This script is running some exe file we are passing three argumnet below custome key word
Want to update script based on input files every time it will take argument from input file
below is the input files should take this input put it into the script.
k.ksh
cd /u/kali/temp
... (8 Replies)
Discussion started by: Kalia
8 Replies
LEARN ABOUT MOJAVE
glubegintrim
GLUBEGINTRIM(3G) GLUBEGINTRIM(3G)
NAME
gluBeginTrim, gluEndTrim - delimit a NURBS trimming loop definition
C SPECIFICATION
void gluBeginTrim( GLUnurbs* nurb )
void gluEndTrim( GLUnurbs* nurb )
PARAMETERS
nurb Specifies the NURBS object (created with gluNewNurbsRenderer).
DESCRIPTION
Use gluBeginTrim to mark the beginning of a trimming loop, and gluEndTrim to mark the end of a trimming loop. A trimming loop is a set of
oriented curve segments (forming a closed curve) that define boundaries of a NURBS surface. You include these trimming loops in the defini-
tion of a NURBS surface, between calls to gluBeginSurface and gluEndSurface.
The definition for a NURBS surface can contain many trimming loops. For example, if you wrote a definition for a NURBS surface that resem-
bled a rectangle with a hole punched out, the definition would contain two trimming loops. One loop would define the outer edge of the rec-
tangle; the other would define the hole punched out of the rectangle. The definitions of each of these trimming loops would be bracketed by
a gluBeginTrim/gluEndTrim pair.
The definition of a single closed trimming loop can consist of multiple curve segments, each described as a piecewise linear curve (see
gluPwlCurve) or as a single NURBS curve (see gluNurbsCurve), or as a combination of both in any order. The only library calls that can
appear in a trimming loop definition (between the calls to gluBeginTrim and gluEndTrim) are gluPwlCurve and gluNurbsCurve.
The area of the NURBS surface that is displayed is the region in the domain to the left of the trimming curve as the curve parameter
increases. Thus, the retained region of the NURBS surface is inside a counterclockwise trimming loop and outside a clockwise trimming loop.
For the rectangle mentioned earlier, the trimming loop for the outer edge of the rectangle runs counterclockwise, while the trimming loop
for the punched-out hole runs clockwise.
If you use more than one curve to define a single trimming loop, the curve segments must form a closed loop (that is, the endpoint of each
curve must be the starting point of the next curve, and the endpoint of the final curve must be the starting point of the first curve). If
the endpoints of the curve are sufficiently close together but not exactly coincident, they will be coerced to match. If the endpoints are
not sufficiently close, an error results (see gluNurbsCallback).
If a trimming loop definition contains multiple curves, the direction of the curves must be consistent (that is, the inside must be to the
left of all of the curves). Nested trimming loops are legal as long as the curve orientations alternate correctly. If trimming curves are
self-intersecting, or intersect one another, an error results.
If no trimming information is given for a NURBS surface, the entire surface is drawn.
EXAMPLE
This code fragment defines a trimming loop that consists of one piecewise linear curve, and two NURBS curves:
gluBeginTrim(nobj);
gluPwlCurve(..., GLU_MAP1_TRIM_2);
gluNurbsCurve(..., GLU_MAP1_TRIM_2);
gluNurbsCurve(..., GLU_MAP1_TRIM_3); gluEndTrim(nobj);
SEE ALSO
gluBeginSurface, gluNewNurbsRenderer, gluNurbsCallback, gluNurbsCurve, gluPwlCurve
GLUBEGINTRIM(3G)