The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



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
Replacing a field in pipe delimited TEXT File ravi0435 UNIX for Dummies Questions & Answers 3 01-08-2009 02:54 PM
need help with replacing a certain field... shennanigan83 Shell Programming and Scripting 5 04-09-2008 02:00 AM
replacing a nul field with text DarkHound Shell Programming and Scripting 3 09-04-2007 03:34 PM
Replacing certain field charbel Shell Programming and Scripting 1 04-26-2006 05:00 PM
Replacing the last field of a line. Darek Shell Programming and Scripting 3 08-19-2005 12:45 PM

 
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 Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 01-21-2009
Glyn_Mo Glyn_Mo is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 16
Supressing and replacing the output of a field in Awk

Wondering if anybody can help with changing the output of a field. I'm needing to change the output of a field in this file:

User Process ID Time Active Licences Type
ChangeAdmin (Phys-agsdev/19353 212), start Wed 1/21 6:30 (linger: 1800)
u414013 (Phys-agsdev/19353 1491), start Wed 1/21 12:54 (linger: 1800)
z001429 (Phys-agsdev/19353 788), start Wed 1/21 13:03 (linger: 1800)
u414014 (Phys-agsdev/19353 1009), start Wed 1/21 10:34
z311203 (Phys-agsdev/19353 2368), start Wed 1/21 10:52
u414020 (Phys-agsdev/19353 879), start Wed 1/21 11:43
z311260 (Phys-agsdev/19353 1523), start Wed 1/21 12:17
oracled (Phys-agsdev/19353 555), start Wed 1/21 9:00
u414013 (Phys-agsdev/19353 1717), start Wed 1/21 12:56

The field which says "(linger: 1800)" is field 13. What I want to do is, if it contains "(linger: 1800)", I want it to say "ChangeBase", or if it is blank, I want it to say "CMBase". Here's the code I have, with an if statement, but it has no affect whatsoever!

BEGIN {
print
print "User Process ID Time Active Licence Type"
print
}
NF > 11{changebaselicences++}
NF < 12{cmbaselicences++}
{
if ($13 == / /) {print "CMBase"}
if ($13 ~ /linger/) {print "ChangeBase"}
print $4, $6, $7, $8, $9, $10, $11, $12, $13
}
END {
printf "\nUsers of SYNERGY-ChangeBase: (Total of 11 licenses issued; Total of %-2d", changebaselicences
print " licences in use)"
printf "\nUsers of SYNERGY-CMBase: (Total of 12 licenses issued; Total of %-2d", cmbaselicences
print " licences in use)"
print
}


Many thanks in advance.
 

Bookmarks

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 On




All times are GMT -4. The time now is 09:38 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