I have data in the following form (stored in file1.txt):
<http://stackoverflow> <isA> "website".
<website> <nameIs> <http://stackoverflow>.
Now using grep I want to retrieve the lines where "http://stackoverflow" occurs as the first string i.e. if I split the lines on spaces then http://stackoverflow should be the first string.
Based on this my output should be:
<http://stackoverflow> <isA> "website".
Is it possible to do so using grep or any other linux command. Because if I use: grep http://stackoverflow file1.txt, then I get the output:
<http://stackoverflow> <isA> "website".
<website> <nameIs> <http://stackoverflow>.
i.e. I get both the lines (whereas my desirable output should contain just the first line of file1.txt):
Given a few lines like these in a file called t0:
This command can do the trick. Notice space after the site:
If you choose to use
awk
, you can write something like this:awk
is splitting by space and then checking if first item in the split is<http://stackoverflow>
. If so, print the entire line represented by$0