![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 2
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Oct 2004
Posts: 7
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|