示例:
假设 nowcoder.txt 内容如下:
#include<iostream> using namespace std; int main() { int a = 10; int b = 100; cout << "a + b:" << a + b << endl; return 0; }你的脚本应当输出:
int a = 10; int b = 100; cout << "a + b:" << a + b << endl; return 0; }
#include<iostream> using namespace std; int main() { int a = 10; int b = 100; cout << "a + b:" << a + b << endl; return 0; }你的脚本应当输出:
int a = 10; int b = 100; cout << "a + b:" << a + b << endl; return 0; }
#include<iostream> using namespace std; int main() { int a = 10; int b = 100; cout << "a + b:" << a + b << endl; return 0; }
int a = 10; int b = 100; cout << "a + b:" << a + b << endl; return 0; }
1. tail -5 nowcoder.txt 2. awk 'BEGIN{i=0}{a[i]=$0;i++}END{for(i=NR-5;i<=NR;i++){print a[i]}}' nowcoder.txt