LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 08-30-2011, 08:02 AM   #1
yogeshkumkar
LQ Newbie
 
Registered: Jul 2011
Posts: 2

Rep: Reputation: Disabled
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.
 
Old 08-30-2011, 08:17 AM   #2
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
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.
Old 08-31-2011, 06:03 AM   #3
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
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.
 
Old 08-31-2011, 07:09 AM   #4
yogeshkumkar
LQ Newbie
 
Registered: Jul 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-31-2011, 07:23 AM   #5
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
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.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
A script that removes dubblets lines into a TXT file? frenchn00b Programming 17 11-20-2012 12:04 PM
[SOLVED] Using AWK to print out the first few lines of a txt file mskalak Linux - Newbie 3 07-27-2011 02:58 PM
Copy the contents of a txt file to other txt files (with similar names) by cp command Aquarius_Girl Linux - Newbie 7 07-03-2010 12:54 AM
Finding things on lines of a txt file Jayfrin Programming 3 05-15-2008 08:13 AM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 05:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration