![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Need help in awk
Hi Frnds,
I have a text file confdate.txt with the following format. From_Date 12-02-2007 To_Date 12-03-2007 Now i have two variables say new_todate,new_fromdate in my shell script which contains two new dates,and i want to update the dates in the flat file corresponding to the column using awk. Can you please give me some inputs on this? Thanks in Advance. - Raja. |
|
||||
|
Using awk: $x and $y are the new values to be set
Code:
awk -v new_from_dat=$x -v new_to_dat=$y '{if( $1 ~ /From_Date/) print $1" "new_from_dat; if ( $1 ~ /To_Date/) print $1" "new_to_dat; }' file_name
|
|
||||
|
Could you please explain me both when you find time?
hey its not working ya. $ dt=`date -u +%d-%m-%y` $ $ echo $dt 29-01-08 $ $ cat tst.txt Date 12-01-08 $ $ awk -v dat=$dt -v '{if( $1 ~ /Date/) print $1" "dat;}' tst.txt Usage: awk [-F fs][-v Assignment][-f Progfile|Program][Assignment|File] ... $ $ sed -e 's/Date\(.*\)/Date '$dt'/' tst.txt Date 29-01-08 $ cat tst.txt Date 12-01-08 $ what is wrong with my command? Last edited by smr_rashmy; 01-29-2008 at 01:11 AM.. |
|
||||
|
Quote:
Why you have used -v there? Also, if you want these changes to written on to a file, you have to use "> new_filename" at the end... ie, sed -e 's/Date\(.*\)/Date '$dt'/' tst.txt > temp_new_file |
|
||||
|
Please read carefully my friend...
Quote:
Code:
awk -v dat=$dt '{if( $1 ~ /Date/) print $1" "dat;}' tst.txt >temp
cp temp tst.txt
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|