Sponsored Content
Top Forums Shell Programming and Scripting Date format change in UNIX .dat file Post 302905057 by Akshay Hegde on Monday 9th of June 2014 10:26:26 AM
Old 06-09-2014
Okay try this, it checks each field (column) in a line, if match is true then it will substitute new date format.

Code:
/usr/xpg4/bin/awk 'BEGIN {
            mon="JanFebMarAprMayJunJulAugSepOctNovDec"
           }
          {
	   for(i=1;i<=NF;i++)
	   {
           if(match($i,/...[[:space:]]..?[[:space:]]..../))
            {
             m = substr($i,RSTART,RLENGTH); split(m,A,/ /)
             gsub(m,sprintf("%02d/%02d/%04d",(match(mon,A[1])+2)/3,A[2],A[3]),$i )
            }
	   }
          }1
     ' FS='|'  file


Last edited by Akshay Hegde; 06-09-2014 at 11:42 AM.. Reason: --color--
This User Gave Thanks to Akshay Hegde For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

script to change the date format in a file

i have many files with date format of 6-9-2008 and i want a script that can change the format to 2008-06-09 Thanks (15 Replies)
Discussion started by: shehzad_m
15 Replies

2. Shell Programming and Scripting

How to change date format in file

Hello! I have a textfile that look like this: "83d1:46:2b";"20091008190000";"Rögle BK - Skellefteå";"Swedish" "d4c:46:21";"20091008190000";"Södertälje - Brynäs";"Swedish" "d4b:46:2";"20091008190000";"HV 71 - Färjestad";"Swedish" "838:46:b";"20091010160000";"Skellefteå - HV 71";"Swedish"... (2 Replies)
Discussion started by: condmaster
2 Replies

3. Shell Programming and Scripting

File date format how to change

Hi All, Below are the unix files taken by the help of ls -lrt -rw-r--r-- 1 kbehera Domain Users 293 Jul 27 13:33 sand.txt -rw-r--r-- 1 kbehera Domain Users 4 Jul 27 13:37 sand1.txt -rw-r--r-- 1 kbehera Domain Users 293 Jul 27 15:30 new_sand.txt -rw-r--r-- 1 kbehera Domain Users 0 Jul 27... (2 Replies)
Discussion started by: krupasindhu18
2 Replies

4. 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

5. Shell Programming and Scripting

How to change the format of the date column in a flat file?

Hi, i have a flat file namely temp.txt with this data below ID|name|contact_date 101|Kay|2013-12-26 102|let|2013-12-26 I need to modify the date data in the flat file into MM/DD/YYYY HH24:MI:SS format let me know the code for this. Thank you! (5 Replies)
Discussion started by: srikanth_sagi
5 Replies

6. Shell Programming and Scripting

Change the date and time format in UNIX script.

Hi, I am extracting a date string from the source file like this : 06/05/2014 16:04:00 I want to change it to 05-JUN-14 04.05.00.000000000 PM I basically store the date in a variable. I got solutions to change date in dd-mmm-yyyy format using tr but I guess it works only with the "date"... (8 Replies)
Discussion started by: Varshha
8 Replies

7. Shell Programming and Scripting

Need to change date format in a csv file using awk

Example: Input csv file 00245DLS,Sitel Ocala,12/31/2014,18:45,1.00,7.00,0.00,0.00 00245DLS,Sitel Ocala,12/31/2014,19:00,-1.00,-1.00,-1.00,-1.00 00245HB,Charlotte,01/01/2015,00:00,-1.00,-1.00,-1.00,0.00 Output csv file 00245DLS,Sitel Ocala,2014/12/31,18:45,1.00,7.00,0.00,0.00 00245DLS,Sitel... (8 Replies)
Discussion started by: adit
8 Replies

8. Shell Programming and Scripting

Date format change in a csv file

Hi, We have csv file where date is coming in MM/DD/YYYY HH:MM:SS (06/23/2015 20:59:12) in multiple places But we need to change the date format to DD/Mon/YYYY HH:MM:SS (23/Jul/2015 20:59:12) using shell script. Please let us know how can we achieve the same. (16 Replies)
Discussion started by: dholea
16 Replies

9. Shell Programming and Scripting

Change date format in am/pm in csv files using UNIX

Hi All, I'm new to forum good to hear all. I stuck in converting date format in csv file using unix csv file contains as below ,750,0000000000000000GCJR, ,06/22/2016 14:48:44 I want to convert into as below ,750,0000000000000000GCJR, ,06/22/2016 02:48:44 PM Please reply asap..... (22 Replies)
Discussion started by: Raghureds
22 Replies

10. UNIX for Beginners Questions & Answers

Change date format in a file.

Hi all, I have a file as below, i would like the change the format of the time from "11/7/2019 20:12" to "2019-07-11 20:12:00" in the last coloumn. any awk solution on this. Input: 2,0,695016,1961612,497212,5800804,0,0,161,33,7605,12226,23,10,66,0,0,34,11/7/2019 20:10... (4 Replies)
Discussion started by: Raghuram717
4 Replies
who(1)								   User Commands							    who(1)

NAME
who - who is on the system SYNOPSIS
/usr/bin/who [-abdHlmpqrstTu] [file] /usr/bin/who -q [-n x] [file] /usr/bin/who am i /usr/bin/who am I /usr/xpg4/bin/who [-abdHlmpqrtTu] [file] /usr/xpg4/bin/who -q [-n x] [file] /usr/xpg4/bin/who -s [-bdHlmpqrtu] [file] /usr/xpg4/bin/who am i /usr/xpg4/bin/who am I DESCRIPTION
The who utility can list the user's name, terminal line, login time, elapsed time since activity occurred on the line, and the process-ID of the command interpreter (shell) for each current UNIX system user. It examines the /var/adm/utmpx file to obtain its information. If file is given, that file (which must be in utmpx(4) format) is examined. Usually, file will be /var/adm/wtmpx, which contains a history of all the logins since the file was last created. The general format for output is: name [state] line time [idle] [pid] [comment] [exit] where: name User's login name state Capability of writing to the terminal line Name of the line found in /dev time Time since user's login idle Time elapsed since the user's last activity pid User's process id comment Comment line in inittab(4) exit Exit status for dead processes OPTIONS
The following options are supported: -a Processes /var/adm/utmpx or the named file with -b, -d, -l, -p, -r, -t, -T, and -u options turned on. -b Indicates the time and date of the last reboot. -d Displays all processes that have expired and not been respawned by init. The exit field appears for dead processes and contains the termination and exit values (as returned by wait(3UCB)), of the dead process. This can be useful in determining why a process terminated. -H Outputs column headings above the regular output. -l Lists only those lines on which the system is waiting for someone to login. The name field is LOGIN in such cases. Other fields are the same as for user entries except that the state field does not exist. -m Outputs only information about the current terminal. -n x Takes a numeric argument, x, which specifies the number of users to display per line. x must be at least 1. The -n option can only be used with -q. -p Lists any other process that is currently active and has been previously spawned by init. The name field is the name of the pro- gram executed by init as found in /sbin/inittab. The state, line, and idle fields have no meaning. The comment field shows the id field of the line from /sbin/inittab that spawned this process. See inittab(4). -q (Quick who) Displays only the names and the number of users currently logged on. When this option is used, all other options are ignored. -r Indicates the current run-level of the init process. -s (Default) Lists only the name, line, and time fields. /usr/bin/who -T Same as the -s option, except that the state idle, pid, and comment, fields are also written. state is one of the following char- acters: + The terminal allows write access to other users. - The terminal denies write access to other users. ? The terminal write-access state cannot be determined. /usr/xpg4/bin/who -T Same as the -s option, except that the state field is also written. state is one of the characters listed under the /usr/bin/who version of this option. If the -u option is used with -T, the idle time is added to the end of the previous format. -t Indicates the last change to the system clock (using the date utility) by root. See su(1M) and date(1). -u Lists only those users who are currently logged in. The name is the user's login name. The line is the name of the line as found in the directory /dev. The time is the time that the user logged in. The idle column contains the number of hours and minutes since activity last occurred on that particular line. A dot (.) indicates that the terminal has seen activity in the last minute and is therefore ``current.'' If more than twenty-four hours have elapsed or the line has not been used since boot time, the entry is marked old. This field is useful when trying to determine whether a person is working at the terminal or not. The pid is the process-ID of the user's shell. The comment is the comment field associated with this line as found in /sbin/inittab (see init- tab(4)). This can contain information about where the terminal is located, the telephone number of the dataset, type of terminal if hard-wired, and so forth. OPERANDS
The following operands are supported: am i In the "C" locale, limits the output to describing the invoking user, equivalent to the -m option. The am and i or I must be sepa- am I rate arguments. file Specifies a path name of a file to substitute for the database of logged-on users that who uses by default. ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of who: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, LC_TIME, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. FILES
/sbin/inittab Script for init /var/adm/utmpx Current user and accounting information /var/adm/wtmpx Historic user and accounting information ATTRIBUTES
See attributes(5) for descriptions of the following attributes: /usr/bin/who +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ /usr/xpg4/bin/who +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWxcu4 | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
date(1), login(1), mesg(1), init(1M), su(1M), wait(3UCB), inittab(4), utmpx(4), attributes(5), environ(5), standards(5) NOTES
Superuser: After a shutdown to the single-user state, who returns a prompt. Since /var/adm/utmpx is updated at login time and there is no login in single-user state, who cannot report accurately on this state. The command, who am i, however, returns the correct information. SunOS 5.10 3 Nov 2000 who(1)
All times are GMT -4. The time now is 04:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy