What would
grep '&' input.txt | tail -4
give me? I am new to this and cannot figure out what happens using grep and tail together.
Asked
Active
Viewed 5,122 times
0

MikeCAT
- 73,922
- 11
- 45
- 70

hehe lohri
- 3
- 1
- 2
-
Unless this is part of a script, the question isn't really on-topic and should probably be asked at https://unix.stackexchange.com/ instead. – Lundin Feb 03 '21 at 15:06
-
Pipe doesn't change the commands. Each does what they do separately. All it does is send the output of grep as the input to tail. – stark Feb 03 '21 at 15:07
1 Answers
1
tail -4 when executed with a file would normally print the last four lines of the file
With:
grep '&' input.txt | tail -4
The tail command is being executed on the output of the grep command and so will print the last 4 lines of the output of grep.
If for example there are 50 occurrences of "&" in input.txt, only the last 4 will print.

Raman Sailopal
- 12,320
- 2
- 11
- 18