Question

I want to analyze the most frequentry occuring entries in (column of) a logfile. To write the detail results, I am creating new directories from the output of something along the lines of

cat logs| cut -d',' -f 6 | sort | uniq -c | sort -rn | head -10 | \
awk '{print $2}' |xargs mkdir -p

Is there a way to create the directories with the sequence number of the argument as processed by xargs as a prefix? For e.g. For e.g. "oranges" is the most frequent entry (of the column) the directory created should be named "1.oranges" and so on.

Était-ce utile?

La solution

A quick (and dirty?) solution could be to pipe your directory names through cat -n in their proper order and then remove the whitespace separating the line number from the directory name, before passing them to xargs.

A better solution would be to modify your awk command:

... | awk '{ print NR "." $2 }' | xargs mkdir -p

The NR variable contains the record (i.e. line) number.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top