linux - Formatting text in BASH -
i absolute beginner shell scripting. task make script, show functions used in file (caller , callee). have used objdump, grep, awk etc. output:
000000000040090d <usage>: 000000000040095d <failure>: 400970: e8 98 ff ff ff callq 40090d <usage> 000000000040097f <strton>: 4009bc: e8 9c ff ff ff callq 40095d <failure> 00000000004009c6 <main>: 400a0e: e8 6c ff ff ff callq 40097f <strton> 400a26: e8 32 ff ff ff callq 40095d <failure> 400a41: e8 39 ff ff ff callq 40097f <strton> 400a59: e8 ff fe ff ff callq 40095d <failure> 400a9a: e8 fe ff ff callq 40095d <failure> 400aae: e8 cc fe ff ff callq 40097f <strton> 400ac2: e8 b8 fe ff ff callq 40097f <strton> 400ad1: e8 87 fe ff ff callq 40095d <failure> 400afe: e8 fe 01 00 00 callq 400d01 <set_timeout> 400b1c: e8 3c fe ff ff callq 40095d <failure> 400b26: e8 19 00 00 00 callq 400b44 <print_fib_upto> 400b37: e8 89 00 00 00 callq 400bc5 <print_ackermann>
okay, result should this:
failure -> usage strton -> failure main -> failure main -> print_ackermann main -> print_fib_upto main -> set_timeout main -> strton
but have no idea how accomplish it. i'd know how in c, etc, not here. think right pseudo-code.
if (end of line == ">:") caller == last column; while (end of line == ">") { callee == last column; echo "$caller -> $callee" }
can tell me, how write in bash? thank much, maybe it's silly question, don't know anyting shell yet.
you can use awk:
awk -f'[<>:]+' 'nf==3{p=$(nf-1); next} {print p, "->", $(nf-1)}' file failure -> usage strton -> failure main -> strton main -> failure main -> strton main -> failure main -> failure main -> strton main -> strton main -> failure main -> set_timeout main -> failure main -> print_fib_upto main -> print_ackermann
Comments
Post a Comment