when i run it, it reports wrong numbers. its always zero. I want it to tell me how many lines it found containing the string "C00" (that's C zero zero not the letter O).
the output should be something like this:
System this must be able to run on: all unix systems - linux, sunos, hpux, aix.
You built a nice, complex regex that matches "C00" surrounded by spaces OR at EOL OR at BOL. None of these conditions are TRUE for your file, so no surprise you get a zero count. Try modifying either your regex or your input file.
when i run it, it reports wrong numbers. its always zero. I want it to tell me how many lines it found containing the string "C00" (that's C zero zero not the letter O).
the output should be something like this:
System this must be able to run on: all unix systems - linux, sunos, hpux, aix.
Your code is looking for the number of times C00 preceded by the start of the line or a <space> and followed by a <space> or the end of the line appears on lines after the 1st line in a file named test.log. (And, those conditions are not met on any line in your sample data.)
You didn't say anything about skipping the first input line in your description, but unless you skip one of the input lines, the number of lines containing the string C00 should be 4; not 3.
Since you're using an array in your code, I will make the (hopefully not too wild) assumption that you also want to search for other strings on the same invocation of your script.
To meet your stated requirement: "tell me how many lines it found containing the string C00" and expand that to also tell you how many lines it found containing the string 463 (note how many lines contain; not how many times does the string appear), you could try something more like:
Of course, instead of using printf and reading the list of strings into your script from standard input, you could define the strings in another file or hardcode them into a BEGIN clause in an awk script.
With the sample data you provided in a file named test.log, the above script produces the output:
If your requirements are not what you stated before and you can't figure out how to modify the code above to get what you need, please restate your requirements clearly and provide sample input and output that match your requirements.
The same awk code should work on any recent system that has awk, but on a Solaris/SunOS system, you'll need to use /usr/xpg4/bin/awk or nawk instead of the default awk.
This User Gave Thanks to Don Cragun For This Post:
so the command i posted was being used to search for multiple patterns in big files. it's suppose to be more efficient. and it was working up until recently. i'm trying to figure out what went wrong.
Good evening, Im newbie at unix specially with awk
From an scheduler program called Autosys i want to extract some data reading an inputfile that comprises jobs names, then formating the output to columns for example
1.
This is the inputfile:
$ more MapaRep.txt
ds_extra_nikira_usuarios... (18 Replies)
Using ksh to call a function which has awk script embedded.
It parses a long two element list file, filled with text numbers (I want column 2, beginning no sooner than line 45, that's the only known thing) . It's unknown where to start or end the data collection, dynamic variables will be used. ... (1 Reply)
Hello experts,
I'm stuck with this script for three days now. Here's what i need.
I need to split a large delimited (,) file into 2 files based on the value present in the last field.
Samp: Something.csv
bca,adc,asdf,123,12C
bca,adc,asdf,123,13C
def,adc,asdf,123,12A
I need this split... (6 Replies)
Hi,
I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files.
To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Hi
I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it
The code is that:
{
if (NF==17){
print $0
}else{
fields=NF;
all=$0;
while... (2 Replies)
Hi Experts,
I am adding a column of numbers with awk , however not getting correct output:
# awk '{sum+=$1} END {print sum}' datafile
2.15291e+06
How can I getthe output like : 2152910
Thank you..
# awk '{sum+=$1} END {print sum}' datafile
2.15079e+06 (3 Replies)
Actually I got a list of file end with *.txt
I want to use the same command apply to all the *.txt
Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics.
For example:
I got the file below:
file1.txt
file2.txt
file3.txt... (4 Replies)