The UNIX and Linux Forums  


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
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 9 06-08-2009 07:11 AM
Find the position of a string and replace with another string bab123 Shell Programming and Scripting 6 01-21-2009 04:14 AM
search in finding position of a string in avariable smr_rashmy Shell Programming and Scripting 2 02-08-2008 10:58 PM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
Print lines with search string at specific position HealthyGuy Shell Programming and Scripting 4 12-04-2006 09:47 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 Rate Thread Display Modes
  #1 (permalink)  
Old 02-09-2009
ganesh_248 ganesh_248 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 41
Search for a string and replace the searched string in the same position

Hi All,

My requisite is to search for the string "0108"(which is the year and has come in the wrong year format) in a particular column say 4th column in a tab delimited file and then replace it with 2008(the correct year format) in the same position where 0108 was found..The issue is the last two digits in "0108" tells the year..The file may contain "0109","0110" and so on...i need to replace the correct year depending on the last two digits of the string..How do i go about??please help me....

eg

00000000 0 +00000000.00 2008/12/29 11:06:04 0108/12/29 10:05:37 00521363

i need to change this to

00000000 0 +00000000.00 2008/12/29 11:06:04 2008/12/29 10:05:37 00521363

Thanks in advance!!!
  #2 (permalink)  
Old 02-09-2009
Whiteboard's Avatar
Whiteboard Whiteboard is offline
Registered User
  
 

Join Date: Feb 2009
Location: @........
Posts: 111
use this...

awk '{sub (/0108/,"2008"); print }' infile
  #3 (permalink)  
Old 02-09-2009
ganesh_248 ganesh_248 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 41
This is not working whiteboard.....it jus replaces the string and displays since print statement is given in AWK.... i need to replace in the actual file itself.....
  #4 (permalink)  
Old 02-09-2009
Whiteboard's Avatar
Whiteboard Whiteboard is offline
Registered User
  
 

Join Date: Feb 2009
Location: @........
Posts: 111
Redirect it to a new file..

awk '{sub (/0108/,"2008"); print }' infile > outfile
  #5 (permalink)  
Old 02-09-2009
ganesh_248 ganesh_248 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 41
The file contains many numerical values ...so there may be many places where 0108 occurs...i need to find the string 0108/ and search it with 2008...how to do it white???
  #6 (permalink)  
Old 02-09-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,907
Code:
$ sed -e 's/0108/2008/' infile > outfile
  #7 (permalink)  
Old 02-09-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,907
Code:
$ sed -e 's|0108/|2008/|' infile > outfile
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 10:53 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