@tag : Shell Sed Script ruby

awk '{ print "../" $0 }' < filelist.txt

Variables :

uname -a | awk -v h=$HOSTNAME '{ print h ":" $0 }'
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | awk '{ SUM += $1} END { print SUM/1024/1024 }' 

Arrays:

history | awk '{a[$2]++ } END { for(i in a){print a[i] " " i}}' | sort -rn | head

filter :

  cat "$1"  \
| awk -v t=0 't==1 { print $0 } '"/${from}/"'{print $0; t=1}  ' \
| awk -v t=0 "/${to}/{t=1}"'t==0 { print $0 }' \
  > "$1.tmp"

regex

 echo -e '{\n{\n}\n}' | awk -v l=O ' '"/{/"'{++l; print $0 l; }  '"/}/"'{ --l; print $0 l; }  '
 echo -e '{\n{\n}\n}' | awk -v l=3 '{for (i = 0 ; i <= l ; i++) printf ",";  printf ".\n" ; }' 
 echo -e '{\n{\n}\n}' | awk -v l=0 '{for (i = 0 ; i < l ; i++) printf "\t";  }  '"/{/"'{++l; print $0 l; }  '"/}/"'{ --l; print $0 l; }  '

 echo -e '{ one\n{ two\n} two\n} one' | awk -v l=0 '  '"/{/"'{++l; }  {for (i = 0 ; i < l ; i++) printf "\t";  } { print $0 " #" l; } '"/}/"'{ --l; } '


==== RUBY ====

  * http://tomayko.com/writings/awkward-ruby

# thx fb pok:

 #!/usr/bin/env ruby                                                                                                            │+
 # Usage: cat source.txt | ./sploup_pipe.rb                                                                                     │+
 lev = -1; STDIN.each do |line|                                                                                                 │+_
  puts "\t" * ((open = line =~ /^\{/) ? (lev + 1) : (lev)) + line                                                              │+
  [  lev = lev.method(open ? :+ : :-).call 1                                                                                      │+
  : end    

lev = -1; $<.each{|line| puts "\t" * ((open = line =~ /^\{/) ? (lev + 1) : (lev)) + line; lev = lev.method(open ? :+ : :-).call 1}  

MORE

awk.txt · Last modified: 2020/09/08 20:40 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki