Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-30-2011, 08:02 AM
|
#1
|
LQ Newbie
Registered: Jul 2011
Posts: 2
Rep: 
|
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.
|
|
|
08-30-2011, 08:17 AM
|
#2
|
LQ Guru
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
|
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
|
|
0 members found this post helpful.
|
08-31-2011, 06:03 AM
|
#3
|
Senior Member
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339
|
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.
|
|
|
08-31-2011, 07:09 AM
|
#4
|
LQ Newbie
Registered: Jul 2011
Posts: 2
Original Poster
Rep: 
|
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.
|
|
|
08-31-2011, 07:23 AM
|
#5
|
Senior Member
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339
|
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
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 09:50 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|