#include <stdio.h>
int main()
{
printf("This is Main()!\n");
return 0;
}
windeal@ubuntu:~/Windeal/Test$ sed -e ‘2d‘ -e ‘6c \\treturn 1;‘ test.c
#include <stdio.h>
int main()
{
printf("This is Main()!\n");
return 1;
}
windeal@ubuntu:~/Windeal/Test$
windeal@ubuntu:~/Windeal/Test$ sed -f script test.c
#include <stdio.h>
int main()
{
printf("This is MyMain()!\n");
printf("hello!\n");
return 0;
}
windeal@ubuntu:~/Windeal/Test$
No. Name Chinese Math
001 Jack 80 85
002 Jane 90 90
003 Ben 85 90
004 Alice 85 95
windeal@ubuntu:~/Windeal/Test$ awk ‘{print "line:" NR "\t" $1 "\t" $3 "\t" $4}‘ stu.txt
line:1 No. Chinese Math
line:2 001 80 85
line:3 002 90 90
line:4 003 85 90
line:5 004 85 95
windeal@ubuntu:~/Windeal/Test$
windeal@ubuntu:~/Windeal/Test$ awk ‘NR==1 {print} NR>1&&$4==90{print}‘ stu.txt
No. Name Chinese Math
002 Jane 90 90
003 Ben 85 90
windeal@ubuntu:~/Windeal/Test$
windeal@ubuntu:~/Windeal/Test$ awk ‘{if(NR==1) printf "%10s %10s %10s %10s %10s\n",$1,$2,$3,$4,"Sum"}\
NR>=2{Sum=$3+$4
printf "%10s %10s %10s %10s %10s\n",$1,$2,$3,$4,Sum}‘ stu.txt
No. Name Chinese Math Sum
001 Jack 80 85 165
002 Jane 90 90 180
003 Ben 85 90 175
004 Alice 85 95 180
windeal@ubuntu:~/Windeal/Test$
原文地址:http://blog.csdn.net/windeal3203/article/details/38554231