New answers tagged

1

Assuming that they are always the same amount of lines, you could do something like this: sed '/Connect\s*user@localhost on/,+7d' log.file This will remove the line containing Connect user@localhost on and the following 7 lines from the file "log.file" in your current directory. Edit: final solution (well, at least good enough for the OP to alter to his ...


0

$ awk -v RS='[[:space:]]+' \ '{ n[$1]++ }; END { for (i in n) { print i":",n[i] } }' debasish.txt (this is a one-liner, with added newlines and indenting for readability) Set the record separator (RS) to 1-or-more of any kind of whitespace (spaces, tabs, newlines, etc), and then keep count of each number seen ...


0

With GNU bash: # read file to variable $x while read -r n; do x="$x $n"; done < file # set associative array and integer attribute declare -Ai a # count occurrences for i in $x; do a[$i]=${a[$i]}+1; done # output content of associative array for i in {0..9}; do echo $i: ${a[$i]}; done Output: 0: 2 1: 4 2: 1 3: 3 4: 3 5: 2 6: 1 7: 1 8: 2 9: 2


3

If the file can have multiple numbers per line, it is simpler to change that into one per line first and then count. For example: $ tr ' ' '\n' < file| sort | uniq -c 2 0 4 1 1 2 3 3 3 4 2 5 1 6 1 7 2 8 2 9 If you really need verbose output, you could further parse that to: $ tr ' ' '\n' < file| sort | uniq -c | while read cnt ...



Top 50 recent answers are included