Tag Info

New answers tagged

0

I would throw sed in directly after sort and have it write out the files as you want them all in one go: wc -l /group/book/four/word/*|sort -n | sed 'w ./not_as_yet_touched.txt 1,2s/^[0-9 ]*//w ./first_two_lines_without_line_numbers_or_leading_spaces.txt s|.*/||w ./everything_up_to_first_slash_trimmed.txt' As written, sed will still autoprint the ...


0

You get the list of files with pathname expansion: cd /group/book/four/word echo * # or into a file echo * >/path/to/filelist.txt You can delete everything in a line from the start up to (including) the first space (or group of spaces) with this sed command: sed 's/^[^ ] *//g' I don't see what od has to do with that. sed can be limited to the ...


1

Let's use AWK! $ function wordfrequency() { awk 'BEGIN { FS="[^a-zA-Z]+" } { for (i=1; i<=NF; i++) { word = tolower($i) words[word]++ } } END { for (w in words) printf("%3d %s\n", words[w], w) } ' | sort -rn } $ cat your_file.txt | wordfrequency This lists the frequency of each word occurring in the provided file. I know it's not what you asked for, ...


4

Dang. I wrote this whole big answer with an elaborate method of parsing a tar archive - it was cool. But I got to the end and I realized none of it was necessary at all. All you need is sed and a little shell math: set ./file[1-5];i=1 n=;eval "${n:= } sed -n \"$(grep -c '.\|' "$@"| sed 's|\(.*\):\(.*\)|\ $i,$(((\2/5)+(i+=\2)-\2))w \1| ...


5

Using the tools you mentioned + find: get percentage of lines or bytes1 with head -n perc file or head -c perc file, where perc is given by (( count / 5 )), where count is given by wc -l < file or wc -c < file, finally, write the output to corresponding file_20. Note: the / operator rounds down to the nearest integer so any file* with lines/bytes ...


7

So creating a single example to work from: root@crunchbang-ibm3:~# echo {0..100} > file1 root@crunchbang-ibm3:~# cat file1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 ...


2

This seems like what you're looking for. The issue as I see it is that there's always going to be at least 1 user that's logged in, i.e. the one accessing the menu, so you're looking for when the number of user's is 1. $ who | awk '{print $1}' | sort -u | wc -l 1 This takes the output of who and cuts just the first column off, i.e. the usernames, and ...


2

Try something like this: USERS=$(who | wc -l) if [ $USERS = 0 ] then reboot fi Using wc -l print the newline counts. Instead, if you don't use this option wc prints newline, word, and byte counts.


2

Each part gets the integer divide ($((a/b))). If the line number modulo the number of parts ($((a%b))) is not zero then you have to distribute the spare modulo number over the parts. One solution is to give the modulo value number of parts an additional line. SPLIT_NUM_THREADS=15 TOTAL_LINES=52 for((i=0;i<$((TOTAL_LINES%SPLIT_NUM_THREADS));i++)); do ...



Top 50 recent answers are included