So if your file has several fields that you can create an expression for, then that should do it.
If the separator is , then an ignored field is .*,) meaning zero or more (*) of any character (. followed by the field separator (,)
So, to count from the beginnig of the line your expression starts as ^.*,.*, to signify start of record (^) the ignore two fields. You can then tag on 1,1,1, to specify your requirements and the rest doesn't matter if it matches or not.
I think you can end up with:-
From your sample input, I get one less line because the one starting jkhu does not have the correct field separator between fields 2 & 3.
I hope that this helps,
Robin
Note that grep will work as well as egrep (or the preferred syntax grep -E) for the RE being used in this thread.
Note also that the RE suggested works correctly only if there are exactly 6 fields (separated by 5 commas) on each input line. Since BREs and EREs use a greedy match, the RE .*, can match more than one field if there are more than 5 commas on a line. For example, that egrep command will also print the lines:
in addition to lines with 1 in fields 3,4, and 5 that only have 6 fields.
To make it work correctly on a line containing six commas (i.e. 7 fields), you would need to change the RE to:
and you would need to add an additional .*, to the end of that RE for each additional field in your input file.
Alternatively, we could use an RE that only matches non-comma characters in each of the first two fields:
which will only print lines with 1 in fields 3, 4, and 5 as long as there are at least six fields on each line. ([^,]* is an RE that matches zero or more occurrences (*) of any character that is not a comma ([^,]) followed by a comma (,). And, the leading ^ in the entire RE anchors the match to the start of the line.)
Is there a way to grep for something and then print out 10 lines after it.
for example if I want to grep for a word, then output the following 10 or whatever number of lines after the word. (5 Replies)
Using shell scripts, I use grep to find the word “error” in a log file:
grep error this.log.
How can I print or get the line 3 lines below the line that word “error” is located?
Thanks in advance for your response. (9 Replies)
Hi All,
I have a log file and I want to parse the logfile with a script.A sample text is shown below:
I would grep on "return code " on this file. Any idea how the lines above and below the grep patterns could also be extracted.
Thanks!
nua7
The runLoggingInstall return code is 0... (3 Replies)
Executed the following if conditions .. and got different results .
only (( )) gave correct o/p with all scenarios .
Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition.
And why each condition gave different result.
1.... (2 Replies)
hi,
I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command
Here are my simple script
After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Hi All,
I'm trying to grep for 3 patterns in a string of gibberish. It so happens that each line is appended by a date/time stamp and i was able to figure out how to extract only the datetime.
here is the string..
i have to display
tinker tailor soldier spy
Please can some help... (2 Replies)
Hello everyone,
I am trying to create function or script to send email from an address book file.
Here is the file format i have,
Susan:Miller:M:123 Main Street:Philadelphia:PA:17101:666-645-6666:Susan.Miller@gmail.com:07/12/1979 Robert:Langan:S:32 North Avenue:San... (5 Replies)
Hi all,
I have two files, chap.txt and complex.txt.
chap.txt looks like this:
a
d
l
m
r
k
complex.txt looks like this:
a c d e l m n j
a d l p q r
c p r m
......... (7 Replies)
HI
My doubt may be basic one but I need to get it clarified..
When i use "if" condition that checks for many AND, OR logical conditions
like
if ]; then
return 0
fi
Even the if condition fails it returns as zero.. Any clue..
But if i add else condition like
if ]; ... (2 Replies)
Need a script that can find text in a file and replace it accordingly.
This is the file I have:
while IFS=',' read -r f1 f2 f3
do
{
nohup /home/testuser/dbmaintenance/sys_offline_maintenance.sh $f1 $f2 $f3 > $f2.out &
}
done < "/home/testuser/dbmaintenance/week1offlineserver.txt"
In... (4 Replies)