Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 28th, 2005, 6:35 PM   #1
ojschubert
Newbie
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 ojschubert is on a distinguished road
edit a text file

Hi,

I'm a bit of a newbie so bare with me. I'd like to edit a number in a text doucment. The document looks like this:

row1: 20
row2: 40
row3: 49

I basically just want to be able to change these numbers. So far I've been able to get these numbers into a c-program by calling a shell script that uses grep and gawk. Now based on the results of my c-program I'd like to call another script that modifys the numbers in the txt document. I think I might need to use the grep and gawk again along with sed but am not really sure.

Can someone please help me get started out.

Thanks

OJ

Last edited by ojschubert; Feb 28th, 2005 at 8:13 PM.
ojschubert is offline   Reply With Quote
Old Apr 14th, 2005, 2:40 PM   #2
sirclif
Newbie
 
Join Date: Oct 2004
Posts: 7
Rep Power: 0 sirclif is on a distinguished road
how do you want to change the numbers? you to through each line and seperate the "row#" from the actual number pretty easy with gawk by setting the field seperator to ": "

gawk -F ": " -v OFS=": " '{print $1,$2}' textfile.txt

this tells gawk that the field seperator for each record (each line) is a colon and a space. the -F option sets the input field seperator. -v tells gawk that a variable is going to be set, in this case OFS (output feild seperator).

this line will just print out the textfile.txt. if you wanted to change the number to the line number you would use

gawk -F ": " -v OFS=": " '{print $1,NR}' textfile.txt

otherwise you'll have to do some decision making on how to change the second field, and insert it into the $2 slot.

hope this helps a little
sirclif is offline   Reply With Quote
Old Apr 18th, 2005, 8:28 AM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
how about using the string substitution of SED?
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:35 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC