LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-09-2010, 08:34 AM   #1
KBriggs
Member
 
Registered: Jun 2009
Posts: 35

Rep: Reputation: 15
file editing


Hey all,


I want to do sonme testing of the nodes on a cluster I am using, testing to see if they run mpi. So I need to check every node by itself first.

which means that I need a machinefile that lists one node at a time:

node2

for example

I want to write a script to test each node in order: in pseudocode:

for i in 2:n
open machinefile
sed s/i-1/i/ #replace the previous number with the new one, will this work?
execute mpi call
do something with the return value
end


So: can someone show me how to do this? I am completely new to shell scripts, so the syntax is what is slowing me down rather than the logic. In the end, this should do something like:


Edit machinefile to contain

node2

run mpi on node 2, and tell me if it worked


Edit machinefile to contain

node3

run mpi on node 3, and tell me if it worked

etc

But I really only need help with the editing the file part of it

Last edited by KBriggs; 06-09-2010 at 08:35 AM.
 
Old 06-09-2010, 08:47 AM   #2
KBriggs
Member
 
Registered: Jun 2009
Posts: 35

Original Poster
Rep: Reputation: 15
#!/bin/bash
for i in {2..71}
do
echo node2 | sed s/[0-9]*/$i/
done





That just appends the value of i before the node2... how can I make is replace the 2 with i?


EDIT:

This works:

#!/bin/bash
for i in {2..71}
do
echo node2 | sed s/\[0-9]\/$i/
done

but when I try to make it act on the file:

#!/bin/bash
for i in {2..71}
do
sed s/\[0-9]\/$i/ <machinefile >machinefile
done

I just get an empty file at the end. Ideas?

Last edited by KBriggs; 06-09-2010 at 09:01 AM.
 
Old 06-09-2010, 12:47 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by KBriggs View Post
Code:
#!/bin/bash
for i in {2..71}
do
  sed s/\[0-9]\/$i/ <machinefile >machinefile
done
I just get an empty file at the end. Ideas?
Yup. Can't redirect from a file to the same file.
Either use a tmp file, or sed with -i.


Cheers,
Tink

P.S.: Use code tags
 
  


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
appending to file, or editing a file ibabhelix Linux - Newbie 7 11-02-2009 06:11 PM
read-only file system error when editing a config file smallfrowne Linux - Newbie 5 02-19-2008 06:06 PM
editing a very large HTML file (or, extracting URLs from a file) Chriswaterguy Linux - Software 3 11-27-2007 06:07 PM
? on editing a file steve_f60 Linux - Software 4 09-20-2005 05:22 PM
file editing newdummy Linux - Newbie 5 03-18-2005 07:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:34 PM.

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