The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How can i truncate filenmes? Calum UNIX for Dummies Questions & Answers 11 07-30-2008 03:30 PM
Truncate Log files anonymous1 Shell Programming and Scripting 1 10-21-2007 04:05 PM
Truncate File contain rinku Shell Programming and Scripting 2 05-30-2007 03:43 AM
truncate wtmp rocker40 UNIX for Dummies Questions & Answers 1 11-04-2004 02:57 PM
Truncate what is It? rocker40 UNIX for Dummies Questions & Answers 2 10-11-2003 04:40 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-14-2007
Registered User
 

Join Date: Aug 2007
Posts: 2
Exclamation *** Truncate certain field ***

I have a file in which I need to truncate 15th field to have only one character

like Put --> P

and if i have no value in 15th field, it should be "O" (Other)

would really appreciate the reponses, thnx in advance
Reply With Quote
Forum Sponsor
  #2  
Old 08-14-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Here is a pointer .

It would be better if you could post a sample input and output if this is not what you are looking for

Code:
cat 3
start|end|first
another||quick
Code:
awk -F"|" 'BEGIN{OFS="|"} { if ( length($2) ) { $2 = substr($2, 0, 1) } else { $2 = "O" } print }' 3
start|e|first
another|O|quick

Last edited by matrixmadhan; 08-14-2007 at 10:51 AM. Reason: better output
Reply With Quote
  #3  
Old 08-15-2007
Registered User
 

Join Date: Aug 2007
Posts: 2
Thanks mate, works pretty well that's exactly wat I was looking for
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0