The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Emergency UNIX and Linux Support !! Help Me!!
.
google unix.com



Emergency UNIX and Linux Support !! Help Me!! Post your urgent questions here for highest visibility. Posting a new thread to this forum requires Bits. We monitor this forum to help people with emergencies, but we do not guarantee response time or answers. This forum is "best effort" only. Members who reply to posts here receive a bonus of 1000 Bits per reply.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
wrong output in perl script namishtiwari Shell Programming and Scripting 2 07-03-2009 07:35 AM
tr command giving wrong output usha rao Shell Programming and Scripting 8 05-08-2009 08:13 AM
Sort command giving wrong output usha rao Shell Programming and Scripting 8 04-07-2009 09:54 AM
Command display output on console and simultaneously save the command and its output satimis UNIX for Dummies Questions & Answers 7 01-25-2009 08:27 PM
Printing to a Savin - Size of output wrong h1timmboy AIX 2 02-28-2006 09:19 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-2009
ganesh_248 ganesh_248 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 41
Unhappy getting wrong output with AWK command!!!

i have a file which gets appended with 9 records daily and the file keeps growing from then...i use to store the previous day files count in a variable called oldfilecount and current files count as newfilecount.my requirement is that i need to start processing only the new records from the file....i mean only if newffilecount > oldfilecount and only fetch the current days 9 records and process it...the no of records which is 9 as of now might vary later..so i just need to fetch the records which has come for today neglecting all the previous days records and process the current records alone...

i tried

awk 'NR>$oldfilecount {print $0}' $eachfile | sed 's/"//g' > outfile

but i m getting all the records displayed...even the old records :-(

but when i give

awk 'NR>64 {print $0}' $eachfile | sed 's/"//g' > outfile i get only the current days records...

How do i get my job done...since the oldfilecount variable keeps changing and based on that i need to filter out the old records and fetch only the new records and process it...

Thanks in advance!
  #2 (permalink)  
Old 09-23-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,770
The ' character prevents variable expansion.
Code:
awk -v oldfilecount=$oldfilecount 'NR>oldfilecount' $eachfile | sed 's/"//g' > outfile
  #3 (permalink)  
Old 09-23-2009
dr.house dr.house is offline
Registered User
  
 

Join Date: Dec 2008
Location: Switzerland
Posts: 229
Ad hoc:

Code:
# more file.old
old text
old text
old text
# more file.new
old text
old text
old text
new text
new text
new text
Code:
# diff --suppress-common-lines file.old file.new | egrep '^[<|>]' | sed 's/[<|>] //'
new text
new text
new text
  #4 (permalink)  
Old 09-23-2009
ganesh_248 ganesh_248 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 41
Thank You Dr.house for your timely help

---------- Post updated at 07:40 PM ---------- Previous update was at 07:39 PM ----------

Quote:
Originally Posted by jim mcnamara View Post
The ' character prevents variable expansion.
Code:
awk -v oldfilecount=$oldfilecount 'NR>oldfilecount' $eachfile | sed 's/"//g' > outfile
Thank you for clarifying me...Now the script is working fine..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On




All times are GMT -4. The time now is 11:58 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-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0