LinuxQuestions.org
Review your favorite Linux distribution.
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 11-07-2008, 01:15 PM   #1
sumitdevbharadwaj
LQ Newbie
 
Registered: Nov 2008
Posts: 20

Rep: Reputation: 0
Need to update some file abc in my script xyz.sh


Hi All,

This is related to shell scripting, if anybody can help me.

I have a situation in which there is a file 'abc' :
#cat abc
students=1000
classes=20
teachers=50

Now I want to write a script in which I call file abc and update 'classes' to 30. so that new file looks like:
#cat abc
students=1000
classes=30 # done bold to clarify.
teachers=50

How can I do this? Can anybody please let me know?

Lots of thanks.
 
Old 11-07-2008, 02:39 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Sed, amongst others, can do this:

sed -ibak 's/classes=20/classes=30/' infile

The -ibak creates a backup (infile.bak in this case) of the original file before changing it.

I'm not sure if this is homework, so it's up to you to find out what is going on and 'script' it ;-)

Hope this helps.
 
Old 11-07-2008, 04:21 PM   #3
sumitdevbharadwaj
LQ Newbie
 
Registered: Nov 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks a lot...it works.
 
Old 11-07-2008, 04:32 PM   #4
sumitdevbharadwaj
LQ Newbie
 
Registered: Nov 2008
Posts: 20

Original Poster
Rep: Reputation: 0
And suppose if there is some attribute rooms whose value I dont know. But whatever it may be I want to set it to 100.
Then what will be the changes in the command???
 
Old 11-07-2008, 04:55 PM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Not sure what it is you are asking. Could you give an example (or 2)?
 
Old 11-08-2008, 12:38 AM   #6
The_Kernel
LQ Newbie
 
Registered: Nov 2008
Posts: 19

Rep: Reputation: 0
Quote:
Originally Posted by sumitdevbharadwaj View Post
And suppose if there is some attribute rooms whose value I dont know. But whatever it may be I want to set it to 100.
Then what will be the changes in the command???
Code:
sed 's/rooms=.*/rooms=100/' -i abc
That's assuming that the "rooms" attribute is the only thing on the line.
 
Old 11-09-2008, 01:37 AM   #7
sumitdevbharadwaj
LQ Newbie
 
Registered: Nov 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Oh Thanks The Kernel...it is working fine.
 
  


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
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM
Sed doesn't update file in bash script chilebiker Programming 4 06-14-2007 08:25 AM
awk syntax to print particular record of xyz file? johnpaulodonnell Linux - Newbie 4 06-14-2007 07:47 AM
service xyz start instead of /etc/init.d/xyz start stefaandk Fedora 3 08-01-2006 08:00 PM
update script from a file knobby Linux - General 7 01-11-2002 11:01 AM

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

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