Sed/awk command to convert number occurances into date format and club a set of lines
Hi,
I have been stuck in this requirement where my file contains the below format.
It follows the below pattern.
Line 1: Start Time
Line 2: Report Name and User
Line 3: Identifier
Line 4: End Time
In the following lines, the 2nd block is missing the End Time and the 3rd block is missing the Identifier.
The requirement is to
1. convert all lines starting with "20" into date format i.e. YYYY/MM/DD
2. Merge block from Start Time till End time separated by commas.
3. Ignore blocks that that don't have the end time.
4. Add a blank space in the block which doesn't contain identifier.
5. If possible, separate Report Name and User Name with comma.
The output should basically look like the below.
I used the if loop for addressing the requirements but the script slows down when run for large files and hence I'm looking for a faster solution using sed or awk.
Can anyone please help me out here ?
Last edited by Scrutinizer; 10-13-2015 at 04:23 AM..
Reason: code tags
Citing Don Cragun: "If you are using a Solaris/SunOS system, use /usr/xpg4/bin/awk or nawk instead of awk ."
Try a pure shell solution as well:
It's quite difficult to sync in on those records with elements missing and fields consisting of several words. So the above is far from elegant and may benefit from some polishing...
That helped to a major extent.
I'm looking into additional cases where there are multiple identifiers in the file and would attempt tweaking the code. I'll ask your help if I fail.
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)
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)
Could you tell me how to convert the following dates?
If I have m/d/yyyy, I want to have
0m/0d/yyyy. I want my dates to always be 8 digits.
In other words, I want a 0 inserted whenever the month or day is a single digit.
My issue is first I need to use FS="," to get field $4 for the... (7 Replies)
Hi All,
Following is my issue.
$MAIL_DOC = test.txt
test.txt contains the following text .
This process was executed in the %INSTANCE% instance on %RUNDATE%.
I am trying to execute the following script
var=`echo $ORACLE_SID | tr `
NOW=$(date +"%D")
sed -e... (3 Replies)
How to convert date format such as 7/18/2015 to the number of month from requesting date 'date' in sh scripting ?
Let say I have output in my log.txt -> 7/18/2015. How I convert it to the full number of month starting from 'date' till 7/18/2015 in shell scripting ? Thanks in advance. (1 Reply)
Hi,
Just trying to get to grips with sed and awk for some reporting for work and I need some assistance:
I have a file that lists policy names on the first line and then on the second line whether the policy is active or not.
Policy Name: Policy1
Active: yes
Policy... (8 Replies)
Looking for some help and usually when I do a search this site comes up. Hopefully someone can give me a little direction as to how to use one of these two commands to achieve what I'm trying to do.
What am I trying to do?
I need to take the time value in epoch format returned from the... (5 Replies)
is there a way with sed to removed more than one set of lines in one line?
so i mean
sed ${firstElem},${lastIndex}d web.xml > web1.xml
this will delete lines between ${firstElem},${lastIndex}
i want in the same line to do somethinkg like this (doesn't work so far)
sed... (3 Replies)
I have a website. I have a directory within it with over a hundred .html files. I need to change a date within every file. I don't have an easy way to find/replace.
I need to change 10/31 to 11/30 on every single page at once. I tried the command below but it didn't work. Obviously I don't know... (3 Replies)
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)