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
editing ELF file tejuwala Linux 1 05-17-2008 11:22 PM
Editing file rahul303 Shell Programming and Scripting 4 09-23-2007 10:49 PM
Editing File using awk/sed Mohammed Shell Programming and Scripting 4 05-16-2007 11:00 AM
Editing the File using Awk awk_beginner Shell Programming and Scripting 3 04-06-2007 10:43 AM
Help with editing file dsravan Shell Programming and Scripting 4 01-31-2007 01:59 PM

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

Join Date: Dec 2005
Posts: 20
File editing using awk

Hi All,
I have a file, say test.dat which is "|" separated. It has 50K records in it. One of the field in the file has the data in the format 'mm/dd/yyyy'. I need to edit the file by changing the format to 'yyyy/mm/dd' in the same field where as the rest of the data remain untouched. Please review the example mantioned below.

test.dat
---------
abcd|ret|12/22/2004|adsf
cdfe|re|05/23/2004|fg
fs|tre|08/22/1889|tref

outputfile(same test.dat)
---------
abcd|ret|2004/12/22|adsf
cdfe|re|2004/05/23|fg
fs|tre|1889/08/22|tref

All I know about AWK, it will be much faster than any other scripting language. Even I prefer to do the same in the commad line itself.
Thanks in advance.

Thanks & Regards,
Rin11... :-)
  #2 (permalink)  
Old 11-23-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
BEGIN {
   FS=OFS="|"
}
{
  split($3, f3, "/")
  $3=f3[3] "/" f3[1] "/" f3[2]
  print
}
  #3 (permalink)  
Old 11-23-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
Code:
awk -F"|" '{ printf "%s|%s|%d/%d/%d|%s\n", $1,$2,substr($3,7,4),substr($3,1,2),substr($3,4,2),$4}'  filename
Closed Thread

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 05:49 AM.


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