p will be set to 2 if the line matching any pattern begins with <?xml..., or 1 otherwise. When printing it is counted down until it reaches 0, thus printing 2 or 1 line, resp.
The n = 2 doesn't seem to be necessary for the correct output; maybe a relict from other attempt to the solution?
p will be set to 2 if the line matching any pattern begins with <?xml..., or 1 otherwise. When printing it is counted down until it reaches 0, thus printing 2 or 1 line, resp.
The n = 2 doesn't seem to be necessary for the correct output; maybe a relict from other attempt to the solution?
Hi Rüdiger,
Note that the last line of the sample input in post #1 was:
If 987skj29 had been included in the pattern file my code would print that line while the code you suggested in post #9 would not. Of course both of our scripts might pick up the 1st (perhaps non-matching line) from a subsequent log file if that sample line had not been in the last log file processed in a batch by find -exec. To avoid that problem, I probably should have included an additional three lines in my script, changing:
to:
to stop an erroneous printing of a continuation line when we switch to a new input log file.
Quote:
Originally Posted by pred55
Hi Don
Thank you for the script, when I executed it I was seeing all the matching lines against the patterns in the pattern.txt file but even if the line is starting with
its not populating the second line. Could you please help me with with that.
Hi pred55,
With the sample input you provided in post #1, the script I suggested produces the output:
exactly matching the output you requested in post #1.
Please post a sample of a sequence of lines in your real data (from pattern.txt and from one of your *.log files that was not processed correctly by the code I suggested.
This User Gave Thanks to Don Cragun For This Post:
.
.
.
If 987skj29 had been included in the pattern file my code would print that line while the code you suggested in post #9 would not.
.
.
.
Thanks for pointing a weakness out that would need additional measures to prevent errors from happening. But: it WOULD print out that line but with a false second line - the last read X which would keep its value when getline failed.
Possible remedies: Check the getline status if (1 == getline X) $0 = $0 RS X or set X = "".
I have a text file which is generated when the batch job is run. This batch may take few mins to run. When completed, the last line of the text file would be process completed. I need a shell script which will wait for this file till the process completed is printed in it, once found, it would move... (2 Replies)
So, there is a large file where I have to conduct several search using bash shell scripting.
The file is like this:
TITLE and AUTHOR ETEXT NO. Aspects of plant life; with special reference to the British flora, 56900 by Robert Lloyd... (1 Reply)
Hi folks,
I am new for shell script, I hope somebody to help me to write shell script
My requirement is below steps
1. I have apache access.log i.e located in /var/log/httpd/
Ex.
127.0.0.1 - - "GET... (14 Replies)
All,
i have a file text.log:
cover6
cover3
cover2
cover4
other file is abc.log as :
0
0
1
0
Then I have a excel file result.xls that contains:
Name Path Pass
cover2
cover3
cover6
cover4 (1 Reply)
Hi,
Need your help for this scripting issue I have. I am not really good at this, so seeking your help.
I have a file looking similar to this:
Hello, i am human and name=ABCD.
How are you?
Hello, i am human and name=PQRS.
I am good.
Hello, i am human and name=ABCD.
Good bye.
Hello, i... (12 Replies)
Hi,
I am trying to create a shell script in unix platform, hence will need info on how to start and any ideas from you guys. million thx.
Objective: Shell script to search all entries from 1 file(a.out) to all other files and extract the search output to 1 file (c.out).
Situation,
1)... (8 Replies)
Have to read one file say sourcefile containing several words and having another folder containing several files.
Now read the first word of Sourcefile & search it into the folder consisting sevral files, and create another file with result. We hhave to pick the filename of the file in which... (3 Replies)
Hi,
We Perfrom Loads to the database through a Perl script which generates a statistics file. I need to read the statistics. the Statistics file looks something like below:
Process Beginning - 08-26-2010-23.41.47
DB2 CONNECTION SUCCESSFUL!
Ready to process and load file: FILENAME
# of... (2 Replies)
Hi,
I've a shell script e.g.
#!/bin/bash
echo "Enter the next hop id"
read nhid
echo "enter the IP address"
read IP
echo "enter the interface name"
read name
echo "enter the enable/disable state"
read state
exit 0
now from this script i want to search strings in another (.cam)
... (6 Replies)
I need to count the number of files which have a search string, but counting the file only once
if search string is found.
eg: File1: Please note that there are 2 occurances of "aaa"
aaa
bbb
ccc
aaa
File2: Please note that there are 3 occurances of "aaa"
aaa
bbb
ccc... (1 Reply)