Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Extract date and time part from filename Post 303033694 by RudiC on Wednesday 10th of April 2019 09:34:46 AM
Old 04-10-2019
Hmmmm - not quite clear yet when you want the dots, and when the printf format strings, or when both... See how far this gets you:



Code:
awk '
FNR == 1        {FILENR++
                }
FILENR <= 2     {CNT++
                 CHFM[CNT] = $1
                 RGEX[CNT] = $2
                 DOTS[CNT] = $3
                 FMTS[CNT] = $4
                 next
                }
                {printf "%s", $0
                 for (j=4; j<=5; j++)   {TMP = $j
                                         PTR = 0
                                         for (i=1; i<=CNT; i++) if (match (TMP, CHFM[i]))       {printf "|%s|%s|%s|%s|%s", PTR + RSTART, RLENGTH, CHFM[i], DOTS[i], FMTS[i]
                                                                                                 TMP = substr (TMP, RSTART+RLENGTH)
                                                                                                 PTR += RSTART + RLENGTH - 1
                                                                                                }
                                        }
                 print ""
                }
'  FS=","  *format.csv FS="|" OFS="|" RECORD
SOURCE|LOGIN|SERVER|ABC_123_YYYYMMDD_V01P1234YYMMDDHHMISS.txt|ABC_123_V01P.YYYYMMDD.HHMISS.txt|CATEGORY|9|8|YYYYMMDD|........|%Y%m%d|26|6|YYMMDD|......|%y%m%d|32|6|HHMISS|......|%H%M%S|14|8|YYYYMMDD|........|%Y%m%d|23|6|HHMISS|......|%H%M%S

These 2 Users Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Insert date/time within a filename

Hi Guys, I need to script the renaming of files as followins: files: firstjd secondjo thirdjv My script needs to insert the date/time infront of the last 2 characters of the filenames above, any ideas greatly received :) the letters before the last 2 characters could change, I'm only... (7 Replies)
Discussion started by: cooperman
7 Replies

2. Shell Programming and Scripting

Extract date from filename and create a new file

Hi, i have a filename CRED20102009.txt in a server 20102009 is the date of the file ddmmaaaa format the complete route is /dprod/informatica/Fuentes/CRED20102009.csv i want to extract the date to create a new file named Parameters.txt I need to create Parameters.txt with this... (6 Replies)
Discussion started by: angel1001
6 Replies

3. Shell Programming and Scripting

how to update date part with new increment date time

hi experts, my requirement is like this i need to develop a shell script to update date part with new incremental date time in file some 'X' which is kept at some server location incrementing every two hours.as i am new to this scripting i need support from u people,thanx in advance (1 Reply)
Discussion started by: amanmro
1 Replies

4. Shell Programming and Scripting

Extract date from filename and set timestamp

I have lots of files in this format: dvgrab-2003.06.29_15-30-24.mpg The numbers represents the date and time (YYYY.MM.DD_HH-MM-SS) How can I extract the dates from the filenames, and use the dates in the file timestamp? I guess this can be done by using "find", "sed" and "touch"? Can... (6 Replies)
Discussion started by: qwerty1234
6 Replies

5. Shell Programming and Scripting

append a filename with system date and time

Hi, There are similar kind of posts, but none seems like working for me. Please correct me if I'm wrong. I need append/rename file abc.txt with file processed date and time like abc_systemdatetimestamp.txt and move it to different folder. for example I have /source/data/abc.txt ... (1 Reply)
Discussion started by: amsn08
1 Replies

6. UNIX for Dummies Questions & Answers

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv OTP_UFSC_20120530000000_prom.csv... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

7. Programming

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My code: if then set "subscriber" "promplan" "mapping" "dedicatedaccount" "faflistSub" "faflistAcc" "accumulator"\ "pam_account"; for i in 1 2 3 4 5 6 7 8;... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

8. Shell Programming and Scripting

Extract a part of a filename containing a particular word

Hi All, Thanks in Advance Shell Script or Perl Script I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv... (7 Replies)
Discussion started by: aealexanderraj
7 Replies

9. UNIX for Dummies Questions & Answers

Extract Date part from the filename

Hi All, I have incoming source files abcmmyy.txt I need to extract the mmyy part from the filename and pass that to a variable . I really appreciate your quick response on this. Thanks raj (7 Replies)
Discussion started by: rajeevm
7 Replies

10. UNIX for Beginners Questions & Answers

How to extract date and time from filename?

Hi, I'm totally new in sell script and working with a shell code. I want to extract the date and time from the filenames. The filenames are different but all of them begins with WI_ SCOPE_: WI_SCOPE_DATA_CHANGE_2017-09-12_15-30-40.txt WI_SCOPE_BACK_COMPLETE_QUEUE_2017-09-12_15-31-40.txt... (5 Replies)
Discussion started by: Home
5 Replies
KPRINTF(9)						   BSD Kernel Developer's Manual						KPRINTF(9)

NAME
device_printf, printf, snprintf, vprintf, vsnprintf, uprintf, ttyprintf, tprintf, aprint -- kernel formatted output conversion SYNOPSIS
#include <sys/systm.h> void device_printf(device_t, const char *format, ...); void printf(const char *format, ...); void printf_nolog(const char *format, ...); int snprintf(char *buf, size_t size, const char *format, ...); void vprintf(const char *format, va_list ap); int vsnprintf(char *buf, size_t size, const char *format, va_list ap); void uprintf(const char *format, ...); void ttyprintf(struct tty *tty, const char *format, ...); #include <sys/tprintf.h> tpr_t tprintf_open(struct proc *p); void tprintf(tpr_t tpr, const char *format, ...); void tprintf_close(tpr_t tpr); void aprint_normal(const char *format, ...); void aprint_naive(const char *format, ...); void aprint_verbose(const char *format, ...); void aprint_debug(const char *format, ...); void aprint_error(const char *format, ...); void aprint_normal_dev(device_t, const char *format, ...); void aprint_naive_dev(device_t, const char *format, ...); void aprint_verbose_dev(device_t, const char *format, ...); void aprint_debug_dev(device_t, const char *format, ...); void aprint_error_dev(device_t, const char *format, ...); void aprint_normal_ifnet(struct ifnet *, const char *format, ...); void aprint_naive_ifnet(struct ifnet *, const char *format, ...); void aprint_verbose_ifnet(struct ifnet *, const char *format, ...); void aprint_debug_ifnet(struct ifnet *, const char *format, ...); void aprint_error_ifnet(struct ifnet *, const char *format, ...); int aprint_get_error_count(void); DESCRIPTION
The printf() family of functions allows the kernel to send formatted messages to various output devices. The functions printf() and vprintf() send formatted strings to the system console. The device_printf() function is identical to printf(), except that it prefixes the log message with the corresponding device name. The printf_nolog() function is identical to printf(), except it does not send the data to the system log. The functions snprintf() and vsnprintf() write output to a string buffer. These four functions work similarly to their user space counterparts, and are not described in detail here. The functions uprintf() and ttyprintf() send formatted strings to the current process's controlling tty and a specific tty, respectively. The tprintf() function sends formatted strings to a process's controlling tty, via a handle of type tpr_t. This allows multiple write opera- tions to the tty with a guarantee that the tty will be valid across calls. A handle is acquired by calling tprintf_open() with the target process as an argument. This handle must be closed with a matching call to tprintf_close(). The functions aprint_normal(), aprint_naive(), aprint_verbose(), aprint_debug(), and aprint_error() are intended to be used to print autoconf(9) messages. Their verbosity depends on flags set in the boothowto variable, through options passed during bootstrap; see boothowto(9) and Interactive mode in boot(8): AB_SILENT silent mode, enabled by boot -z. AB_QUIET quiet mode, enabled by boot -q. AB_VERBOSE verbose mode, enabled by boot -v. AB_DEBUG debug mode, enabled by boot -x. The aprint_*() functions have the following behaviour, based on the above mentioned flags: aprint_normal() Sends to the console unless AB_QUIET is set. Always sends to the log. aprint_naive() Sends to the console only if AB_QUIET is set. Never sends to the log. aprint_verbose() Sends to the console only if AB_VERBOSE is set. Always sends to the log. aprint_debug() Sends to the console and the log only if AB_DEBUG is set. aprint_error() Like aprint_normal(), but also keeps track of the number of times called. This allows a subsystem to report the number of errors that occurred during a quiet or silent initialization phase. For the aprint_*() functions there are two additional families of functions with the suffixes _dev and _ifnet which work like their counter- parts without the suffixes, except that they take a device_t and struct ifnet *, respectively, as first argument, and prefix the log message with the corresponding device or interface name. The aprint_get_error_count() function reports the number of errors and resets the counter to 0. If AB_SILENT is set, none of the autoconfiguration message printing routines send output to the console. The AB_VERBOSE and AB_DEBUG flags override AB_SILENT. RETURN VALUES
The snprintf() and vsnprintf() functions return the number of characters placed in the buffer buf. This is different to the user-space func- tions of the same name. The tprintf_open() function returns NULL if no terminal handle could be acquired. SEE ALSO
printf(1), printf(3), snprintb(3), boot(8), autoconf(9), boothowto(9) CODE REFERENCES
sys/kern/subr_prf.c HISTORY
The sprintf() and vsprintf() unsized string formatting functions are supported for compatibility only, and are not documented here. New code should use the size-limited snprintf() and vsnprintf() functions instead. In NetBSD 1.5 and earlier, printf() supported more format strings than the user space printf(). These nonstandard format strings are no longer supported. For the functionality provided by the former %b format string, see snprintb(3). The aprint_normal(), aprint_naive(), aprint_verbose(), and aprint_debug() functions first appeared in BSD/OS. BUGS
The uprintf() and ttyprintf() functions should be used sparingly, if at all. Where multiple lines of output are required to reach a process's controlling terminal, tprintf() is preferred. BSD
January 21, 2011 BSD
All times are GMT -4. The time now is 04:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy