Tag Info

New answers tagged

1

A simple way to do what the question asks for, in one command: awk '{ if (NR <= 1000) print > "piece1"; else print > "piece2"; }' bigfile or, for those of you who really hate to type long, intuitively comprehensible commands, awk '{ print > ((NR <= 1000) ? "piece1" : "piece2"); }' bigfile


1

I think that split is you best approach. Try using the -l xxxx option, where xxxx is the number of lines you want in each file (default is 1000). You can use the -n yy option if you are more concerned about the amount of files created. Use -n 2 will split your file in only 2 parts, no matter the amount of lines in each file. You can count the amount of ...


5

The easiest way is probably to use head and tail: $ head -n 1000 input-file > output1 $ tail -n +1001 input-file > output2 That will put the first 1000 lines from input-file into output1, and all lines from 1001 till the end in output2


0

Another perl: $ w | head -1 | perl -nle 'print +(split /load average:/)[-1]' 0.42, 0.49, 0.63


5

You can also use awk: $ w | head -1 | awk '{print $10,$11,$12}' 0.80, 0.84, 0.93 Or, if the number of fields is variable, use: $ w | head -1 | awk '{print $(NF-2),$(NF-1),$NF}' 0.81, 0.82, 0.91 Or, the much more elegant (thanks @Letitzia): $ w | head -1 | awk -F "load average: " '{print $2}' Sed: $ w | head -1 | sed 's/.*load average: *//' Perl: ...


3

Normally I'd just use the ${parameter#word} bash parameter expansion. It expands $parameter, deleting word (which can be a pattern) from the start. In your case, something like: line=... echo ${line#*load average: } Making it a function: get_load() { w | head -n 1 | { read -r line; echo ${line#*load average: }; } }


3

If you want only last numbers you can use grep: $ w | grep -Po 'load average: \K.*' 0.07, 0.13, 0.09



Top 50 recent answers are included