I am trying to understand what the grep command in ubuntu is trying to do here.
The contents of my test file is given below
When I grep for 3 dots (...) without the parenthesis as follows I would expect the output to match the first 3 characters in the above file. But the output I am seeing shows that it matches more than 3 characters in some lines. Can anyone help me here understand why the 3rd line is being shown to match more than 3 characters.
If you are looking for just three character on a line (not zero, one or two & not four or more) then you need to mark the beginning and end of the line in your expression. The carat ^ marks the beggining and the dollar $ is the end of a record. With these you can set the expression and search exactly:-
Using grep is great, but you have to be strict with your expression if that's what you need. You have to refine your expression(s) so that:-
you don't miss data that you want
you don't get data that you don't want
There is a good book by O'Reilly for sed & awk which has good explanations for expressions. It is worth a read. You don't have to get full into sed & awk but it's great to know as it will help in so many ways.
hi to all,
i am writing a simple file program in C which has to take a string of length n as input and match that input string with first n character of the line in file. if it does not match it has to compare with first n characters of next line. i am finding it difficult to know how exactly to... (2 Replies)
hii all
i have a file a which contains some thing like this
strand smthg position
+ yyx 3020
- yyw 10,000
now i have another file (file2) which contains the data starting from 1 to n positions
i want to refer first file if + ... (4 Replies)
I need to write an Unix script to report the number of SQL files in my home directory, ending with .sql . The script should, also, be checking whether there is a file with an underscore in its name. If that is the case, the underscore should be converted to a dash (‐); for example... (1 Reply)
I want to check where our programmers are using "delete" instead of "delete" in their C++ code:
grep -r delete *cpp | grep -v
However, this statement and variations thereof (escaping with backslash (\), single quotes ('), double quotes ("), accolades ({)) always lead to the following message:... (2 Replies)
hi
i am writing a hangman script and am having trouble checking the correct letters against the word
i need the script to compare the word against the letters guessed that are correct so once all the letters within the word have been guessed it will alow me to create a wining senario
this must... (1 Reply)
hi
i am writing a hangman script and am having trouble checking the correct letters against the word
i need the script to compare the word against the letters guessed that are correct so once all the letters within the word have been guessed it will alow me to create a wining senario
eg
... (3 Replies)
Dear all,
I'm stuck on a certain problem regarding counting the number of characters in one line and then adjusting the number of characters of another line to this number.
This was my original input data:
@HWI-ST471_57:1:1:1231:2079/2... (4 Replies)
Hi there,
I have a file with lines like these:
0105:ffff0000:001b:01f4:25:434
0299:ffff0000:0009:01f4:2:319
02d2:ffff0000:000e:01f4:2:507
The above values are split up using ":" characters.
I would like capture each value, no matter what length.
Take for example the first line... (8 Replies)
how do i check if the first character is a parenthese in pattern matching?
if ] obviously doesnt work. How do I use it to compare so it doesnt try to use it to group. (5 Replies)
please send the logic or program to find the matching characters between two strings
for ex string1 :abc
string2 :adc
no .of matching characters is 2(a,c) (9 Replies)