Results 1 to 3 of 3
Hello, everyone. I'm somewhat new to linux and I'm having a problem trying to automatically update a text file. Maybe someone here can help me out.
I have a text ...
- 12-30-2010 #1Just Joined!
- Join Date
- Dec 2010
- Posts
- 3
Updating a single line in a text file
Hello, everyone. I'm somewhat new to linux and I'm having a problem trying to automatically update a text file. Maybe someone here can help me out.

I have a text file called namelist.wps. In this file there is a line that reads:
I have to automatically update the year, month, and day of month. I set values for the year, month, and day of month using the following code in a c-shell script:Code:start_date = '2010-12-26_12:00:00', '2010-12-26_12:00:00',
After I do this, how do I update year, month, and day of month, without changing any of the other lines in the namelist.wps file?Code:set y1 = `date +%Y` set m1 = `date +%m` set d1 = `date +%d`
- 12-30-2010 #2Just Joined!
- Join Date
- Dec 2010
- Posts
- 3
I think sed could be used to do this but I don't know how.
- 12-31-2010 #3Just Joined!
- Join Date
- Dec 2010
- Posts
- 3
Ok. This is the code for the script I am trying to use:
The out put in the newnamelist.wps file is :Code:#!/bin/csh set y1 = `date +%Y` set m1 = `date +%m` set d1 = `date +%d` set date1 = ${y1}-${m1}-${d1}_12:00:00 cat namelist.wps | sed 's/^.*start_date.*$/ start_date = '$date1', '$date1',/' >newnamelist.wps exit 0
The Problem is that I need single quotes around the dates so it reads as follows:Code:start_date = 2010-12-31_12:00:00, 2010-12-31_12:00:00,
Someone please help.Code:start_date = '2010-12-31_12:00:00', '2010-12-31_12:00:00',


Reply With Quote