You can remove the tab space from multiple lines by selecting those lines and pressing Shift+tab. Shift+tab is used to give a reverse tab, i.e. tab in the opposite direction, so this should work almost wherever you want to reverse tab.
AWK
Use AWK
- that's the simplest as it can get:
awk '/yellow/,0' textfile.txt
Sample run
$ awk '/yellow/,0' textfile.txt
yellow
red
orange
more orange
more blue
this is enough
Grep
You could also use grep
with --after-context
option, to print certain amount of lines after the match
grep 'yellow' --after-context=999999 textfile.txt
For automatic setting of context, you could use $(wc -l textfile.txt)
. The basic idea is that if you have a very first line as a match and you want to print everything after that match, you will need to know the number of lines in file minus 1. Luckly, --after-context
won't throw errors about the number of lines, so you could give it number completely out of range, but in case you don't know it, total number of lines will do
$ grep 'yellow' --after-context=$(wc -l < textfile.txt) textfile.txt
yellow
red
orange
more orange
more blue
this is enough
If you want to shorten the command --after-context
is the same option as -A
and $(wc -l textfile.txt)
, will expand to number of lines followed by file name. So that way you type textfile.txt
only once
grep "yellow" -A $(wc -l textfile.txt)
Python
skolodya@ubuntu:$ ./printAfter.py textfile.txt
yellow
red
orange
more orange
more blue
this is enough
DIR:/xieerqi
skolodya@ubuntu:$ cat ./printAfter.py
#!/usr/bin/env python
import sys
printable=False
with open(sys.argv[1]) as f:
for line in f:
if "yellow" in line:
printable=True
if printable:
print line.rstrip('\n')
Or alternatively without printable
flag
#!/usr/bin/env python
import sys
with open(sys.argv[1]) as f:
for line in f:
if "yellow" in line:
for lines in f: # will print remaining lines
print lines.rstrip('\n')
exit()
Best Answer
Surround your search string with double quotes: