Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #8 (permalink)  
Old 10-29-2009
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,199
it should print the entire file once with the changed fields. It works fine on your sample data in the original post.
Please show WHAT you have and HOW do you run it.
Sponsored Links
  #9 (permalink)  
Old 10-29-2009
Registered User
 

Join Date: Oct 2009
Posts: 6

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 synoptime tz, $4) ; print  } 1' dateblock=$(date +%m%d%y)     tz=$(date +%Z) synoptime=$synoptime modtest > modtest2

awk ' (( NF == 4 ) && ( /^\./ )) && ( $4 !~ /^[0-9]/ ) {  gsub(/[0-1][0-9][0-3][0-9][0-9][0-9][0-2][0-9][E][DS][T]/, dateblock synoptime tz, $3) ; print } 1' dateblock=$(date +%m%d%y)     tz=$(date +%Z) synoptime=$synoptime modtest >> modtest2

awk ' (( NF == 4 ) && ( /^\./ )) && ( $4 ~ /^[0-9]/ ) {  gsub(/[0-1][0-9][0-3][0-9][0-9][0-9][0-2][0-9][E][DS][T]/, dateblock synoptime tz, $4) ; print } 1' dateblock=$(date +%m%d%y)     tz=$(date +%Z) synoptime=$synoptime modtest >> modtest2

awk ' (( NF == 3 ) && ( /^\.T/ )) && ( $3 ~ /^[0-9]/ ) {  gsub(/[0-1][0-9][0-3][0-9][0-9][0-9][0-2][0-9][E][DS][T]/, dateblock synoptime tz, $3) ; print } 1' dateblock=$dateblock tz=$tz synoptime=$synoptime modtest >> modtest2


I have also tried it as one big awk block, but so far it's only outputting the last line of the modtest file:

(synoptime, dateblock, tz defined earlier in script)


Code:
awk 'BEGIN {dateblock=$dateblock; tz=$tz; synoptime=$synoptime}
{
     if  (( NF == 5 ) && ( /^\./ ))
     { gsub(/[0-1][0-9][0-3][0-9][0-9][0-9][0-2][0-9][E][DS][T]/, dateblock synoptime tz, $4) }

     if  ((( NF == 4 ) && ( /^\./ )) && ( $4 !~ /^[0-9]/ ))
     { gsub(/[0-1][0-9][0-3][0-9][0-9][0-9][0-2][0-9][E][DS][T]/, dateblock synoptime tz, $3) }

     if ((( NF == 4 ) && ( /^\./ )) && ( $4 ~ /^[0-9]/ ))
     { gsub(/[0-1][0-9][0-3][0-9][0-9][0-9][0-2][0-9][E][DS][T]/, dateblock synoptime tz, $4) }

     if ((( NF == 3 ) && ( /^\.T/ )) && ( $3 ~ /^[0-9]/ )) 
     { gsub(/[0-1][0-9][0-3][0-9][0-9][0-9][0-2][0-9][E][DS][T]/, dateblock synoptime tz, $3) }
}
END { print } ' modtest

  #10 (permalink)  
Old 10-29-2009
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,199

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 synoptime tz, $4) }

( NF == 4 ) && ( /^\./ ) && ( $4 !~ /^[0-9]/ ) {
   gsub(/[0-1][0-9][0-3][0-9][0-9][0-9][0-2][0-9][E][DS][T]/, dateblock synoptime tz, $3) }

( NF == 4 ) && ( /^\./ ) && ( $4 ~ /^[0-9]/ ) {
   gsub(/[0-1][0-9][0-3][0-9][0-9][0-9][0-2][0-9][E][DS][T]/, dateblock synoptime tz, $4) }

( NF == 3 ) && ( /^\.T/ ) && ( $3 ~ /^[0-9]/ ) {
   gsub(/[0-1][0-9][0-3][0-9][0-9][0-9][0-2][0-9][E][DS][T]/, dateblock synoptime tz, $3) }
1
' dateblock="$(date +%m%d%y)" tz="$(date +%Z)" synoptime="$synoptime" modtest > modtest2

  #11 (permalink)  
Old 10-29-2009
Registered User
 

Join Date: Oct 2009
Posts: 6
Perfect! Many thanks!
Sponsored Links
Reply

Bookmarks

Tags
awk, date/time, gsub

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0