cutting lines

Dear All,

Is there a way to cut the lines that have been "head"

Here is what i m trying to do Please advice

there is file name dummy.txt

now i am trying to head this file 4 time by using a loop and every time this file is head with different values

e.g in first instance it will be head -1 for second interval it will be head -20 and so on.

these intevaral are random and are been generated by a counter evertime a script is executed counter bounce with a new value and according to that value file will be "head" four times.

Now the issue is, during the first interval if file is "head 5" times (i.e. head -5) output must be saved with a new file extension, and when its executed second time for (head -10) file should start from (6th value to 16th value and not from 1st to 10th) and so on.

please advice from this point..:confused:

Thankz in advance:cool:

Simple way to do it:

 
head -10 <file_name> | tail -5

what this peice of code is trying to do is: get top ten lines of the file and print last five of those to STD output. you can keep appropriate counters to iterate the loop. Also redirect to file accordingly.

:b:

thnkz for the reply.

the values mentioned here are just an example.

May be this can help you out..

here it is what i am trying to to

For e.g a file name dummy.txt contains value 1-10 coloum wise.

now i want to head this file 4 four times but with different interval (random numbers are generating from a counter.. no help needed for this case)

like in first instant file is head 2 times (head -2 <filename> [output will be 1 2]

now for second time when the file is head let say 4 times (i.e head -4 ) than output should be (3 4 5 6) and not (1 2 3 4).

Similarly, for third and fourth time.

May be this will help ya understand in a better way.

Please help

Thankz in advance.

ok, if I get it right try this:

sed -n '2,6p' <file_name>

this will print lines starting at column 2 to 6.

Substitute 2 & 6 with your loop variables.

let me know if you need more on this.:b:

thankz a million shubhendu

now please help in one more thing

my files also contains spaces:

1

2

3

4

.
.
.

if want to remove these spaces how can i do this.

as the below mentioned command is also counting spaces.

You welcome.

This code will delete blank lines from the file:

 
sed '/^ *$/d' <file_name>

you can either PIPE this or redirect this to a tmp file and do next operation accordingly.

cheers.

:b:

simply awesome bro...

thnkz a million

GOD BLess ya

-----Post Update-----

Dear All,

now m stuck into this

the following command do execute and provide me my desired result

sed -n '2,6p' <file_name>

but now the issue is, if i want that the values are automatically palced in the said file how to do that

like

sed -n '$varaible1,$variable2p' <file_name>

where variable1 and variable2 are the values that will be placed randomly by the script [I have no issue of placing these variable] the only issue is with the command

please help

-----Post Update-----

please help

use DOUBLE quotes.