Visit Our UNIX and Linux User Community


to replace Date format issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting to replace Date format issue
# 1  
Old 08-09-2012
to replace Date format issue

Hi,
I have the below data in a file in one of the path,
Code:
101 02100002111406893401207310900A094101xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  
5200xxxxxxxxxx                          D18000_1  CCDXXXXXXX   JUL 31201207   1140689340000001
622113010547999999999003     000333333334RE  00030137 onee SYSTEM             0140689340000001
62200000 0000999999999001    0000011111CR460 00030135 twoo system             0140689340000002
82000000040015507087000000000000000003571110D18000_1                           140689340000001

Can some one tell me how to read the date from this file which is there in line 1 which is starting with indicator 1 at position 24 to 29
in this example it is 120731
which is in YYMMDD format
I want to replace from 70 to 75 with above date + 2 as 120802 in 2nd line which starts with indicator 5
My output should look like

Code:
101 02100002111406893401207310900A094101xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  
5200xxxxxxxxxx                          D18000_1  CCDXXXXXXX   JUL 31120802   1140689340000001
622113010547999999999003     000333333334RE  00030137 onee SYSTEM             0140689340000001
62200000 0000999999999001    0000011111CR460 00030135 twoo system             0140689340000002
82000000040015507087000000000000000003571110D18000_1                           140689340000001

Can some one please tell me how to do this?
Appreciate your response.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 08-09-2012 at 07:33 AM.. Reason: code tags, please!
# 2  
Old 08-09-2012
If you have gnu date this should do it:

Code:
dt=
ln=1
while read line
do
   [ $ln -eq 1 ] && dt=$(date -d "$(echo "$line" | cut -c24-29) + 2 day" +%y%m%d)
   [ $ln -eq 2 ] && line=$(echo "$line" | cut -c1-69)$dt$(echo "$line" | cut -c76-)
   ((ln++))
   echo "$line"
done < infile > outfile


Previous Thread | Next Thread
Test Your Knowledge in Computers #328
Difficulty: Easy
The Windows ME operating system was released in the year 2006.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date 19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

2. Solaris

Solaris 5.8 Upgrade is causing Date format issue.

Hi I have a JAVA based application in development and production environment. These two environments are exactly identical in terms of OS, hardware and application components. Initially the OS was Solaris 5.6 and the application was working fine in both environments. But later when the OS... (12 Replies)
Discussion started by: Jayant Tripathi
12 Replies

3. UNIX for Dummies Questions & Answers

Rename all Files in a UNIX Directory from one date format to another date format

Hi Unix Gurus, I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
Discussion started by: pchegoor
1 Replies

4. Shell Programming and Scripting

sed command to replace slash in date format only

Hello experts. I haven't been able to find a solution for this using the sed command. I only want to replace the forward slash with string "FW_SLASH" only if there's a number right after the slash while preserving the original number. I have a file containing 2 entries: Original File:... (5 Replies)
Discussion started by: pchang
5 Replies

5. Shell Programming and Scripting

PERL : hhmiss - Date format check and replace

I have a filename, This can be any of any format, I want to check if the filename has hours,mins and seconds part. If it is present, i want to replace it with a " * " (star symbol) output needed: IMP: The time part can be in any pattern. How can this be done?:confused:... (3 Replies)
Discussion started by: irudayaraj
3 Replies

6. Shell Programming and Scripting

Date format check and replace string in PERL

I have got few date format patterns like "yyyymmdd", "yy_mm_dd" etc. There can be any combination of such patterns. I have used add_delta_days to find "yyyy", "yy", "mm", "dd" for the current date and saved them to different variables like "$y1", "$y2", "$m1" etc In one line, i want to... (10 Replies)
Discussion started by: irudayaraj
10 Replies

7. UNIX for Dummies Questions & Answers

Changing from Excel date format to MySQL date format

I have a list of dates in the following format: mm/dd/yyyy and want to change these to the MySQL standard format: yyyy-mm-dd. The dates in the original file may or may not be zero padded, so April is sometimes "04" and other times simply "4". This is what I use to change the format: sed -i '' -e... (2 Replies)
Discussion started by: figaro
2 Replies

8. Shell Programming and Scripting

How to search a date format from a file an replace with a string in PERL

I am very new to Perl. I am struggling so hard to search a date (such as 10/09/2009, 10-09-2009) from a text file and replace with a string (say DATE) using Perl. Please help me out. Thanks in advance. Regds Doren (4 Replies)
Discussion started by: my_Perl
4 Replies

9. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

10. UNIX for Advanced & Expert Users

date issue-find prevoius date in a patricular format

Hi , I have written a shell script that takes the current date on the server and stores it in a file. echo get /usr/home/data-`date '+%Y%d'`.xml> /usr/local/sandeep/GetFILE.ini I call this GetFILE.ini file from an sftp program to fetch a file from /usr/home/ as location. The file is in... (3 Replies)
Discussion started by: bsandeep_80
3 Replies

Featured Tech Videos