LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   cut first 10 lines of file master.txt and paste in ab1.txt and so on (https://www.linuxquestions.org/questions/programming-9/cut-first-10-lines-of-file-master-txt-and-paste-in-ab1-txt-and-so-on-900249/)

yogeshkumkar 08-30-2011 08:02 AM

cut first 10 lines of file master.txt and paste in ab1.txt and so on
 
Hello,

I have a file called master.txt containing 1000 lines.
I want to cut first 10 lines of master.txt and paste in data1.txt then submit a job using command "bsub -K -qio ./run1.txt", when this job is finished,
cut first 10 lines of master.txt and paste (replace) in data1.txt (lines should be overwritten, i mean old 10 lines of data1.txt should be deleted and new lines should be paste) and submit "bsub -K -qio ./run1.txt" and so on.

run1.txt contains a single command "./mod.sh data1.txt . >& zlog1.txt"

Total there should be 100 iterations as there are 1000 lines in master.txt

Please reply if anybody know.
Thanks.

H_TeXMeX_H 08-30-2011 08:17 AM

See:
http://www.grymoire.com/Unix/Sed.html#uh-30

Examples:

Code:

sed -n '1,10 p' test > new
sed -i '1,10 d' test


Reuti 08-31-2011 06:03 AM

Does LSF support array jobs? In GridEngine aka SGE I would submit one array job running 100 instances and depending on the index $SGE_TASK_ID you get for each job it could honor the relevant lines of the master.txt file. The problem I see with your solution is, that you would need either 100 different data1.txt files, or to wait with the next job until the predecessor finished (to avoid overwriting of the previous data1.txt file).

Aha, LSF has the variable LSB_JOBINDEX, so:
Code:

#!/bin/sh
let START=($LSB_JOBINDEX-1)*100+1
echo "I will handle lines from $START on."
sed -n $START,+99p master.txt > $TMPDIR/input.txt
./mod.sh $TMPDIR/input.txt

and submit with bsub -J "data[1-100]" script.sh (I have no access to LSF, but I think you get the idea). The $TMPDIR should be created by LSF unique to each job.

yogeshkumkar 08-31-2011 07:09 AM

Thanks Reuti,
It didnt work.
I have a code like

Code:

#!/bin/sh
i=o
while [$i -lt 400]
do
i = [i + 1]
head -10 master.txt > data1.txt | sed -i '1,10d' master.txt  ## To cut first 10 lines from master and paste to data1.txt
###bsub -K -qio ./run1.txt                                    ## I used to submit the jobs like this, but there will be 1000 jobs for 10000 lines.
./mod.sh data1.txt . >& zlog1.txt                          ## this is the only line of file run1.txt. every time, data1.txt should get first 10 lines from master
###rm downdata2.txt
done

any help to correct this code? because, when I checked the data1.txt stays empty.

Reuti 08-31-2011 07:23 AM

Well, the problem is the pipe, as it won’t get any input - the output is already redirected.

Also the computation of i is not working - the i will be set to a literal [i+1] as text.
Code:

for ((i=1;i<=3991;i+=10)); do
    sed -n $i,+9p master.txt > data1.txt
    ./mod.sh data1.txt . >& zlog1.txt
done



All times are GMT -5. The time now is 09:27 AM.