LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-19-2009, 03:38 PM   #1
keupie
LQ Newbie
 
Registered: Aug 2008
Posts: 9

Rep: Reputation: 0
how to change the content of a file without open it?


I am using condor system to run simulation. Each run I only need to change a number in the input file. For example, for 20 simulations, I have 20 input files. But only a number in the input file is different. How can I change the number without opening each file and changing it manually?

thanks so much.
 
Old 03-19-2009, 03:50 PM   #2
Mark_667
Member
 
Registered: Aug 2005
Location: Manchester, England
Distribution: Ubuntu 20.04
Posts: 383

Rep: Reputation: 30
If I understand you right then Condor (I presume you're talking about http://www.cs.wisc.edu/condor/) needs to read a number from a file to tell it how many input files it should use per run?

The only way you could do this would be to know how many input files it'll need per run in advance or have some way of calculating it. If you do you could probably just use a script to write a file whenever it detects that a previous job has completed (maybe by going off the number of files output or the contents of a log file?). You may want to set this to run automatically in a cron job.
 
Old 03-19-2009, 04:31 PM   #3
keupie
LQ Newbie
 
Registered: Aug 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Mark_667 View Post
If I understand you right then Condor (I presume you're talking about http://www.cs.wisc.edu/condor/) needs to read a number from a file to tell it how many input files it should use per run?

The only way you could do this would be to know how many input files it'll need per run in advance or have some way of calculating it. If you do you could probably just use a script to write a file whenever it detects that a previous job has completed (maybe by going off the number of files output or the contents of a log file?). You may want to set this to run automatically in a cron job.
Yeah. I am using that condor. This can run the 20 jobs at the same time, but at different machines. I have a folder to store the input file for each run. This is the same as I run a program 20 times with different inputs. I want to know in linux, do we have a way to change 20 files with the same name ,in different folders easily? I only need to change the number in the third line to a different number for each file.

thanks
 
Old 03-19-2009, 04:58 PM   #4
keupie
LQ Newbie
 
Registered: Aug 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by keupie View Post
Yeah. I am using that condor. This can run the 20 jobs at the same time, but at different machines. I have a folder to store the input file for each run. This is the same as I run a program 20 times with different inputs. I want to know in linux, do we have a way to change 20 files with the same name ,in different folders easily? I only need to change the number in the third line to a different number for each file.

thanks
I found this command
sed -i 's/-15/-2035/' filename

this works.
 
Old 03-19-2009, 06:10 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,131

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
That may lead to some astonishment - it changes all occurrences of "-15" TO "-2035". Maybe you should just change the data you need to the data you want. Note the 3 after the single quote restricts the update to only the third line.
Code:
sed -i '3s/-15/-20/' filename
There are also simple script solutions to iterate over a director structure to do this automatically in (applicable) all files, but requires knowledge of how you have said directories organized.

Last edited by syg00; 03-19-2009 at 06:11 PM.
 
Old 03-19-2009, 06:20 PM   #6
JaksoDebr
Member
 
Registered: Mar 2009
Distribution: Fedora, Slackware
Posts: 104

Rep: Reputation: 21
Running echo in a shell with output redirection can overwrite file contents. For example:
echo "12" > some-file.txt
will overwrite any existing some-file.txt with 12 as it's content.

By creating a shell script you can populate all the input files with random numbers. Adding the shell script as a cron job will run it without your interaction.

Linux Archive

Last edited by JaksoDebr; 04-02-2009 at 05:08 AM.
 
  


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
Show file Content on File Select HTML stranger_6_7 Linux - General 4 09-24-2007 11:52 PM
Can I change title bar content in an application window? dhave Linux - Desktop 4 09-19-2007 01:27 PM
How to open/popup a new window to display the content of specified text file use Gtk cy163 Programming 1 06-17-2007 03:13 PM
awk and change file content Ayman.mashal Programming 4 06-02-2005 06:03 AM

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

All times are GMT -5. The time now is 05:13 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