Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. foo
  2. bar
  3. foobar
  4. barfoo
  5. last
  6. line
  7.  
  8. foo
  9. bar
  10. foobar
  11.  
  12. $ tac file | sed '1,3d' | tac
  13. foo
  14. bar
  15. foobar
  16.  
  17. $ tac file | awk 'NR==1{next}NR==2{next}NR==3{next}1' | tac
  18. foo
  19. bar
  20. foobar
  21.  
  22. ... | awk '{l[NR] = $0} END {for (i=1; i<=NR-3; i++) print l[i]}'
  23.  
  24. ... | awk '{if (a) print a; a=b; b=c; c=$0}'
  25.  
  26. awk -v n=$(($(wc -l < file) - 3)) 'NR<n' file
  27.  
  28. $ seq 6 | head -n-3
  29. 1
  30. 2
  31. 3
  32.  
  33. awk 'NR>n{print A[NR%n]} {A[NR%n]=$0}' n=3 file
  34.  
  35. Line 1 -> A[1]
  36. Line 2 -> A[2]
  37. Line 3 -> A[0]
  38. Line 4 -> A[1]
  39. Line 5 -> A[2]
  40. ...
  41.  
  42. awk '{if(NR==FNR){c++}else if(FNR<=c-3){print}}' file file
  43.  
  44. for i in {500000..1000000}; do
  45. echo "The quick brown fox jumped over the lazy dog $i" >> file;
  46. done
  47.  
  48. $ for i in {1..10}; do (
  49. time awk '{if(NR==FNR){c++}else if(FNR<=c-3){print}}' file file > /dev/null ) 2>&1 |
  50. grep -oP 'real.*?mK[d.]+';
  51. done | awk '{k+=$1}END{print k/10" seconds"}';
  52. 0.4757 seconds
  53.  
  54. $ for i in {1..10}; do (
  55. time awk '{l[NR] = $0} END {for (i=1; i<=NR-3; i++) print l[i]}' file > /dev/null ) 2>&1 |
  56. grep -oP 'real.*?mK[d.]+';
  57. done | awk '{k+=$1}END{print k/10" seconds"}';
  58. 0.5347 seconds
  59.  
  60. head -n -3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement