LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-30-2009, 11:56 PM   #16
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244

Quote:
Originally Posted by osor View Post
comments):
Code:
..
	if ($6<now && $4==1)
	...
i really doubt 2 dates can be compared when in this format YYYY/MM/DD.
 
Old 07-01-2009, 06:05 AM   #17
magische_vogel
Member
 
Registered: Jun 2009
Posts: 42

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by osor View Post
Probably because I forgot to specify gawk (which has the ARGIND variable). There was also a typo I fixed.

If you want to use nawk, the following should work (I put in some comments):
Code:
#!/usr/bin/awk

FNR==1 { # when we encounter line 1 of a file
	FS=OFS= arg++ ? " " : ";" # arg = 1 for first file, 2 for second
	"date +%Y/%m/%d" | getline now
}
arg==1 {
	if ($6<now && $4==1)
		$4 = 0
	enabled[$1] = $4 # record the enabled status of this username
	print $0 > usersDB.conf
}
arg==2 { print (enabled[$2] ? "" : "#") $0  > access.conf }
You were correct in how to run it:
Code:
./scritpt.awk usersDB.conf access.conf
Your script is working fine except when i run it twice it deactivate already deactivated users i mean it add # to "#F: username" in the access.conf file. is it possible to ignore the already deactivated users in the access.conf file.

#!/usr/bin/gawk -f

FNR==1 { # when we encounter line 1 of a file
FS=OFS= arg++ ? " " : ";" # arg = 1 for first file, 2 for second
"date +%Y/%m/%d" | getline now
}
arg==1 {
if ($6<now && $4==1)
$4 = 0
enabled[$1] = $4 # record the enabled status of this username
print $0 > "usersDB.conf"
}
arg==2 { print (enabled[$2] ? "" : "#") $0 > "access.conf" }

thanks a lot.
 
Old 07-01-2009, 12:21 PM   #18
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by magische_vogel View Post
when i run the script i get the folowing errors:
Another typo (seems to be a theme with me in this thread)! I of course meant
Code:
#!/usr/bin/awk -f
 
Old 07-01-2009, 12:21 PM   #19
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by ghostdog74 View Post
i really doubt 2 dates can be compared when in this format YYYY/MM/DD.
Sure they can (at least in ASCII and its supersets including UTF-8 and all 15 parts of ISO-8859).

String comparison is done as you would expect, and most charsets (including ASCII) are created so that digits follow the normal rules for succession (including 0 < 1). As long as all fields are padded (which in this case they are), the string comparison should suffice for dates.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Good time to use AWK? VeeDubbs Linux - General 9 03-13-2009 10:55 PM
bash script read error and awk ouptut error whited Programming 4 10-16-2007 07:05 PM
Amarok 1.4.5 and some .asf audio filea raylhm SUSE / openSUSE 3 03-25-2007 09:37 AM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 09:19 AM
This is read time !!! neo77777 General 3 11-20-2002 05:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration