If I cat a file
And want to go to the first instance of a particular value - what command would I use?
And then from that point where I jumped to search for another value - but only search from that point forward not before the file?
Thanks~
If I cat a file
And want to go to the first instance of a particular value - what command would I use?
And then from that point where I jumped to search for another value - but only search from that point forward not before the file?
Thanks~
To do yourself, use your editor, such as vi.
>vi filename
/particular {would search for the word particular}
n {would find the next occurrence}
Or, as part of a script would be potentially more involved. And would require a little more info on your intent.
> cat -n uprlwr.fmt | grep "VERSION"
32 VERSION,4,C
That tells me that there is a reference to the word VERSION at the 32nd line in my file. By combining head and tail commands, I can extract a subset of my original file.
pattern1="fox"
pattern2="dog"
awk -v pat1="$pattern1" -v pat2="$pattern2" \
'BEGIN{ found==0}
if(found==0)
{if(index($0, pat1)> 0) {found=NR} }
if(found>0 && index($0, pat2)>0) {print $0} } ' inputfile
This code starts looking for "dog" only after it finds "fox".