![]() |
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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Date comparison with 'string date having slashes and time zone' in Bash only | TariqYousaf | Homework & Coursework Questions | 1 | 10-08-2009 02:27 PM |
| compare file modification date/time to current date/time | Bill Ma | Shell Programming and Scripting | 5 | 08-27-2009 01:02 PM |
| how to convert date time to epoch time in solaris | anshuman0507 | Shell Programming and Scripting | 6 | 08-22-2009 11:28 PM |
| Convert Epoch Time to Standard Date and Time & Vice Versa | DrivesMeCrazy | Shell Programming and Scripting | 5 | 02-07-2009 01:40 AM |
| Processing a log file based on date/time input and the date/time on the log file | primp | Shell Programming and Scripting | 4 | 03-16-2008 11:23 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
AWK and sub/gsub: updating a date/time block
I have a file ("modtest") in which I want to update the last date/time block in the lines beginning with a period. Here is a sample:
Code:
.ROMULT 10150908EDT 10270908EDT 10010908EDT RANGE RAWV2 1.00 .ROMULT 10150908EDT 10270908EDT 10010908EDT FGROUP CHOWANRV 1.00 .RRIMULT 10150908EDT 10270908EDT 10010908EDT RAWV2 1.13 .RRIMULT 10150908EDT 10270908EDT 10010908EDT FGROUP CHOWANRV 1.13 .TSCHNG 10190914EDT 10010908EDT RAWV2 RAWV2 QINE 6 49.72 48.42 47.11 45.81 44.51 43.20 42.43 & 41.65 40.88 40.10 39.32 38.55 38.31 38.08 37.85 37.62 37.38 37.15 & 36.92 36.69 36.55 36.41 36.27 36.13 35.99 35.85 35.71 35.57 & PLOT-TUL Code:
awk ' ( NF == 5 ) && ( /^\./ ) { gsub(/[0-1][0-9][0-3][0-9][0-9][0-9][0-2][0-9][E][DS][T]/, dateblock, $4) ; print } ' modtest
When I run this command, the lines that have 5 fields and begin with a period are changed as follows, but the 4th field that I meant to update does not appear at all: Code:
.ROMULT 10150908EDT 10270908EDT RANGE .ROMULT 10150908EDT 10270908EDT FGROUP .RRIMULT 10150908EDT 10270908EDT FGROUP .SWITCHTS 10150908EDT 10270908EDT FGROUP Any help appreciated. Thanks!Last edited by zaxxon; 10-23-2009 at 10:44 AM.. Reason: code tags also for data and logs please, ty. |
|
||||
|
I defined dateblock earlier in the program, before the awk statement. Unfortunately, the desired hour number is not just system time, but one of (02, 08, 14, 20) under EDT and (01, 07, 13, 19) under EST. I have code earlier in the program that figures out which one is appropriate based on the current system time.
|
|
||||
|
OK, that helped -- thanks!
I was under the impression that gsub would make the substitutions in the matching lines in the input file itself, but that the output would contain both the changed and unchanged lines. All I've been able to make it do so far is output the lines it changes. By chance are there any switches in gsub that might make it do what I want, or do I need to figure out some other way to make it pick up the additional unchanged lines in the proper order? |
|
||||
|
I have been unable to find documentation to tell me how that works exactly -- it seems to print the entire file as well as the changed lines. I can get rid of the duplicates with uniq, but since I need to run a similar command on the same file 4 times, is there a way to have it only print the entire file once?
|
![]() |
| Bookmarks |
| Tags |
| awk, date/time, gsub |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|