Autor |
Nachricht |
|
Titel: Grep and Awk? Modifying text from command line.
Verfasst am: 21.11.2006, 16:41 Uhr
|
|
Anmeldung: 14. Jan 2006
Beiträge: 287
|
|
Does anyone know how to change values (first column) in a file structured like this using grep, awk or some other command line way?
Code:
1 #Variable1
2 #Variable2
3 #Variable3
I can use
Code:
grep Variable1 file.ini
to find instances of each variable, but can't find a good way to implement it...
Also, how do I write a loop in Bash to loop that code, and change it to different values? Ideally I want to change the ini file, run a program. Change the ini file, run the program loads of times to produce different results so I can analyse them. If anyone is interested I'm simulating the flow of information through ant colonies, and want to alter the initial conditions...
Any ideas?
Thanks a lot,
Rich |
|
|
|
|
|
|
Titel: RE: Grep and Awk? Modifying text from command line.
Verfasst am: 21.11.2006, 18:48 Uhr
|
|
Anmeldung: 05. Jul 2006
Beiträge: 127
|
|
|
|
|
|
Titel: RE: Grep and Awk? Modifying text from command line.
Verfasst am: 21.11.2006, 20:16 Uhr
|
|
Anmeldung: 12. Mar 2005
Beiträge: 1005
|
|
sed is your friend, but you need to give more information, what is the first column being changed TO?
1 #Variable1
is 1 supposed to change to something else depending on which VariableX you have in the column?
You have to give more details, not general stuff, but an actual example of the desired outcome with a sample string input. |
_________________ Read more on dist-upgrades using du-fixes-h2.sh script.
New: rdiff-backup script
|
|
|
|
|
|
Titel: RE: Grep and Awk? Modifying text from command line.
Verfasst am: 21.11.2006, 20:45 Uhr
|
|
Anmeldung: 14. Jan 2006
Beiträge: 287
|
|
Sorry, no column 1 just changes to a different value, e.g.
1 #Inital Speed
2 #Inital Angle
might change to
2 #Initial Speed
4 #Initial Angle
I want to automate the setting up (changing this file) and running a program basically. Sorry my explanation wasn't so good!
I'll have a look at sed, thanks! |
|
|
|
|
|
|
Titel:
Verfasst am: 21.11.2006, 22:13 Uhr
|
|
Anmeldung: 14. Jan 2006
Beiträge: 287
|
|
I ended up doing it like so:
Code:
X=0
while [$X -le 100]
do
echo "1 #initial speed" > initialisation.ini
echo "$X #initial angle" >> initialisation.ini
echo "Datafile${X}.csv #initial angle" >> initialisation.ini
echo "all the other variables etc..." >>initialisation.ini
program
done
which seems to work fine... is there a better way of doing this? It seems pointless to rewrite the file everytime I change it, but this does work!
sed looks complex! |
|
|
|
|
|
|
Titel:
Verfasst am: 22.11.2006, 12:49 Uhr
|
|
Anmeldung: 14. Jan 2006
Beiträge: 287
|
|
How do you echo something with a new line in it? e.g. I want to write all those lines to the file, and have resorted to doing it in lots of echo commands, is there a way to get echo to write a carriage return? I tried echo "Line 1/nLine2/nLine3", but that doesn't work... must be easy I imagine, but can't work it out!
Rich |
|
|
|
|
|
|
Titel:
Verfasst am: 22.11.2006, 12:51 Uhr
|
|
Anmeldung: 18. Mar 2004
Beiträge: 3417
|
|
|
|
|
|
Titel:
Verfasst am: 22.11.2006, 13:02 Uhr
|
|
Anmeldung: 05. Jul 2006
Beiträge: 127
|
|
Zitat:
is there a way to get echo to write a carriage return?
enter key
echo "
1 => press enter
2 => press enter
" > my_file |
_________________ astalavista == BSD is dying
http://talks.dixongroup.net/nycbsdcon2006/
|
|
|
|
|
|
Titel:
Verfasst am: 22.11.2006, 17:26 Uhr
|
|
Anmeldung: 14. Jan 2006
Beiträge: 287
|
|
|
|
|
|