Sponsored Content
Top Forums Shell Programming and Scripting Keeping padding in a date field Post 302275830 by cfajohnson on Monday 12th of January 2009 09:38:13 AM
Old 01-12-2009
Quote:
Originally Posted by seanbyrne
Still having a problem though, i'm plugging the variable into a sed command and its still not padding the %e variable:

Code:
CURRENT_DATE="$(date +"%a %b %e")"

sed -n '/^"$CURRENT_DATE"/,$ p' /var/sean/errorlog.log > /tmp/tempfile.tmp


You are not plugging the variable into the sed command; you are giving it a literal string because it is within single quotes.

Code:
CURRENT_DATE=$(date +"%a %b %e")
sed -n "/^$CURRENT_DATE/,$ p" /var/sean/errorlog.log > /tmp/tempfile.tmp

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Arrange date in a field

Hi all, If I have a flat file ID|Location|Date|Hostname|Age|Sex 1|SFO|06/02/24 12:12:34|hawkeye|35|M 2|LAX|06/02/24 13:12:35|sf49ers|30|M 3|OAK|06/02/25 11:12:36|goraiders|27|F 4|PIT|06/02/25 12:12:37|steeler|35|M How can I create an output 1|SFO|02/24/2006 12:12:34|hawkeye|35|M... (6 Replies)
Discussion started by: sabercats
6 Replies

2. Shell Programming and Scripting

handling date field

Hi, Is there any way we could change the date format listed below... date I get is 03302007 (MMDDYYYY) I need to change it to 20070330 (YYYYMMDD) Thanks. (3 Replies)
Discussion started by: mgirinath
3 Replies

3. Shell Programming and Scripting

CSV formatting with prefixing, appending and padding field

Hi I have a very large csv file with some hundreds of thousands of rows of data. The data is in the following format: Up to four alpha numeric characters for the first word. This is either set as 2 characters followed by 2 spaces, or as a single 4character word. This is then followed by an 8... (7 Replies)
Discussion started by: meself
7 Replies

4. Shell Programming and Scripting

date field manipulation

I have a data file. Seperated by "|". The 19 th filed is a date field that occurs like this 11/02/2001 i need to convert into the below format 2001-11-02 for e.g.. i/p o/p should be can somebody throw some light (5 Replies)
Discussion started by: dsravan
5 Replies

5. UNIX for Advanced & Expert Users

change field 2 date format

from this input WEBELSOLAR,29122009,1:1 WIPRO,15062010,2:3 ZANDUREALT,18012007,1:3 i want output as WEBELSOLAR,20091229,1:1 WIPRO,20100615,2:3 ZANDUREALT,20070118,1:3 basically input is in ddmmyyyy format and i was to convert it to yyyymmdd format (1 Reply)
Discussion started by: manishma71
1 Replies

6. Shell Programming and Scripting

Replace date value with another value keeping all as is

Hi forum. How do I change the following date value with another value (while keeping the rest of the line) using sed? The date values can change so I need a general sed command to change the date value within the first quotation marks only. Date values will be coming from 2 different files.... (2 Replies)
Discussion started by: pchang
2 Replies

7. Shell Programming and Scripting

Check if a date field has date or timestamp or date&timestamp

Hi, In a field, I should receive the date with time stamp in a particular field. But sometimes the vendor sends just the date or the timestamp or correctl the date&timestamp. I have to figure out the the data is a date or time stamp or date&timestamp. If it is date then append "<space>00:00:00"... (1 Reply)
Discussion started by: machomaddy
1 Replies

8. Shell Programming and Scripting

Sort, sed, and zero padding date column csv bash scripting

Hello people, I am having problem to sort, sed and zero padding of column in csv file. 7th column only. Input of csv file: 1,2,3,4,5,6,4/1/2010 12:00 AM,8 1,2,3,4,5,6,3/11/2010 9:39 AM,8 1,2,3,4,5,6,5/12/2011 3:43 PM,8 1,2,3,4,5,6,12/20/2009 7:23 PM,8 Output:... (5 Replies)
Discussion started by: sean1357
5 Replies

9. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies
DtMsgLogMessage(library call)											     DtMsgLogMessage(library call)

NAME
DtMsgLogMessage -- logs a message SYNOPSIS
#include <Dt/MsgLog.h> void DtMsgLogMessage( const char* program_name, DtMsgLogType msg_type, const char* format, va_list args); DESCRIPTION
The DtMsgLogMessage function logs the given arguments in one message. The format of the message is specified by format and thus is con- trolled by the application. The format of each logged entry is: *** <Msgtype_string>( <Msg_type>): <Program_name>: PID <Proc_id>: <Date> <The_message> *** [ <Bytes_output>] The value of <Msgtype_string> depends on the value of msg_type. Its value is: INFORMATION if msg_type is DtMsgLogInformation STDERR if msg_type is DtMsgLogStderr DEBUG if msg_type is DtMsgLogDebug WARNING if msg_type is DtMsgLogWarning ERROR if msg_type is DtMsgLogError UNKNOWN for all other values of msg_type <Msgtype_string> is prefaced with the string *** and one space character. <Msg_type> is replaced with the value of the msg_type argument (placed within parentheses). <Program_name> is replaced with the value of the program_name. <Proc_id> is the application's process id. <Date> is the date and time the message is logged. <The_message> is the formatted message including the arguments. <Bytes_output> (enclosed in brackets) is replaced with the number of bytes output for the message and header information. (The number of bytes printed for the line containing <Bytes_output> is not included.). A colon and a space (respectively) are printed after the closing parenthesis for <Msg_type>, <Program_name>, and <Proc_id>. One newline is output after the date and one newline is output after the message. After the message, a line beginning with the string *** is output, followed by a space character, a [ character, the number of bytes printed, a ] character, and,finally, two newlines (one blank line separates messages). The message type string and date specification are localized and thus are retrieved from the current locale's message catalog. It is the application's responsibility to localize the message to be logged. An example log entry is: *** WARNING(3): fontview: PID 12312: Thu Jun 13 16:51:51 1995 The specified font 'fixed' could not be loaded. *** [109] To log a multi-line message, use a single call to DtMsgLogMessage. DtMsgLogMessage attempts to open the following files in the indicated sequence (by calling the fopen function with the a+ option). It uses the first file that is successfully opened. $HOME/.dt/errorlog This file is used only if the environment variable HOME is defined. /var/dt/tmp/$DTUSERSESSION/errorlog This file is used only if the environment variable DTUSERSESSION is defined. <filename>/tmp/<user_name>.errorlog</filename> In this filename, <user_name> is replaced by the user's login name. The login name is determined by using the environment vari- able LOGNAME, if it is defined, or USER, if LOGNAME is not defined. If neither variable is defined, DtMsgLogMessage uses the get- pwuid function to determine <user_name>. DtMsgLogMessage calls DtMsgLogOpenFile to determine where to log the message. If DtMsgLogOpenFile returns NULL, DtMsgLogMessage will output the message to stderr. ARGUMENTS
program_name Specifies a string "tag" to identify the application issuing the message. This is generally an application's argv[0] so the mes- sage can be traced to an executable program. msg_type Specifies the DtMsgLogType structure that defines the message type. See "Structures" in this man page. format Specifies the sprintf format of the message. args Specifies the variable number of arguments needed by format. STRUCTURES
The msg_type argument is specified as a DtMsgLogType enumeration data type, with the following members: DtMsgLogInformation Designates informational messages that do not have to be brought to the user's immediate attention (for example, status informa- tion). It is acceptable to not present messages of this type to the user. DtMsgLogDebug Designates debugging messages written by the application (for example, via a -debug command line option). DtMsgLogStderr Designates messages that an application produces to log the stderr from a child process. DtMsgLogWarning Designates messages for errors that are not severe enough to cause program termination. DtMsgLogError Designates messages for fatal errors that require program termination. RETURN VALUE
None. ENVIRONMENT VARIABLES
The values of the following environment variables determine which file is opened by DtMsgLogMessage: HOME, LOGNAME, USER, and DTUSERSES- SION. See "Description" in this man page for more information. Because DtMsgLogMessage calls the catopen function, it is indirectly influenced by the environment variables that affect catopen, such as LANG, and NLSPATH. See catopen(3) for more information. RESOURCES
None. ACTIONS
/MESSAGES The default mechanism to view the message log is to invoke the Watch Errors action which is located in the Application Manager's Desk- top_Tools folder. ERRORS
/WARNINGS None. EXAMPLES
The following code fragment illustrates how to log a localized warning message: #include <nl_types.h> char *s1, *s2; /* temp strings - catgets may return a pointer to a static buffer */ nl_catd catd = catopen ("app.cat", 0); s1 = strdup (catgets (catd, 4, 10, "string 1")); s2 = strdup (catgets (catd, 4, 10, "string 2")); DtMsgLogMessage (argv[0], DtMsgLogWarning, "%s %s", s1, s2); FILES
See DtMsgLogOpenFile(3). SEE ALSO
DtMsgLogOpenFile(3), DtMsgLogSetHandler(3) DtMsgLogMessage(library call)
All times are GMT -4. The time now is 08:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy