|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
head command?
Hi, I'm currently taking a unix class and I'm stuck in one of our assignments.
Problem is, I need to extract X number of lines from a flat text file in bash. i.e. lines 1-10 or line 11-20 My professor said use the head command, but I can't seem to make it extract anything but the first X number of lines. I need to be able to specify the starting line aswell. Appriciate any help. Mads. |
|
#2
|
|||
|
|||
|
head or it brother tail cannot do what you want, see manpages.
the chip way is the fantastic 'sed' sed -n '4,19p' inputfilename >outoutfilename prints line 4 till line 19 nota start (4) have to be <= end (19) this also works with strings sed -n '/start/,/end/p' in >out sure perl can it also |
|
#3
|
|||
|
|||
|
Thanks for the response.
Mads. |
|
#4
|
||||
|
||||
|
Code:
perl -e 'while(<>) { print "$_" if ++$L > 3 and $L < 20; }' < input_file
|
|
#5
|
|||
|
|||
|
Found the method using head and tail:
i.e. head -30 inputfilename | tail -20 > outputfilename will output lines 11-30 from input i believe Your example using sed makes more sense though. Thanks again. Mads. |
|
#6
|
|||
|
|||
|
hokus:
why do you spend time to invent the horror: head -30 inputfilename | tail -20 > outputfilename in *nix (and in life) there are a lot of alternatives to do the same job. to kill a fly... use an atomic bomb. |
|
#7
|
|||
|
|||
|
Well, why learn liniar algebra and stay up sleepless nights writing structured essays? .. because my grade depends on it, that's why
![]() I don't attempt to reason with the course curriculum, I just do my best to learn and sometimes ask the experts (like yourself) when nessesary. Cheers, |
|
#8
|
|||
|
|||
|
to grate my left ear
i can use my left hand but over my head, coming down, i also can use my rigth hand. both work. no time for that, but sure 1+0 could be (x + sin(y) - cos(z) + sqrt(q)) / bessel(a,c) ![]() |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > BSD Help > head command? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|