Quantcast
Channel: Show all lines before a match - Ask Ubuntu
Browsing latest articles
Browse All 8 View Live

Answer by Quasímodo for Show all lines before a match

To print all lines before the match,perl -pe 'exit if /foo/' fileawk '/foo/{exit} 1' file

View Article



Answer by user.dz for Show all lines before a match

FreeBSD (including MacOS) version does have such feature.Well -B -1 works, it shows all the lines before the match from the beginning of the file.... | grep -B -1 -- "foo"Same for -A -1 , it shows all...

View Article

Answer by ks1322 for Show all lines before a match

Show ALL lines before a matchYou can use large enough number for -B option of grep. For example if your know that input size is no more than 999 you can use it with -B option:... | grep -B 999 -- "foo"

View Article

Answer by JoL for Show all lines before a match

Current solutions except schrodigerscatcuriosity's print the file contents even when there's no match. schrodigerscatcuriosity's involves using tac and so requires reading the whole input before...

View Article

Answer by Quasímodo for Show all lines before a match

Including the match,sed '/foo/q' fileIt is better to quit sed as soon as a match is found, otherwise sed would keep reading the file and wasting your time, which would be considerable for large...

View Article


Answer by Cyrus for Show all lines before a match

With GNU sed. Print all lines, from the first to the line with the required string.sed '0,/foo/!d' file

View Article

Answer by schrodingerscatcuriosity for Show all lines before a match

Here's a solution with sed, given the content of file.txt:barbazmoofooloozoocommand including patterntac file.txt | sed -n '/foo/,$p' | tacoutputbarbazmoofooexcluding patterntac file.txt | sed -n -e...

View Article

Show all lines before a match

I want to show all lines before a match, not only 10, or 7, or 14 for example, as explained in How do I fetch lines before/after the grep result in bash?.How can I do it? It doesn't matter if the...

View Article

Browsing latest articles
Browse All 8 View Live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>