reformat date, awk and sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reformat date, awk and sed
# 1  
Old 06-04-2008
reformat date, awk and sed

The command below is getting me the output I need.
awk -F"," ' {
if ($6 = 475) print "@@"$3 " " "0000" $10 "0" $1 "00000000" $8}' ${DIR1}${TMPFILE1} | sed -e 's/@@1//g' > ${DIR2}${TPRFILE}

Output:
900018732 00004961160200805160000000073719

Now I need to incorporate this sed command to reformat the date to mmddyy:
sed 's/^\(..\)\(..\)\(..\)\(..\)$/\3\4\2/'

Any ideas...
# 2  
Old 06-04-2008
Like this?
Code:
echo '900018732 00004961200200805160000000073719'| sed -e 's/.*\(200.\{5\}\)00000000.*/\1/g' -e 's/^..\(..\)\(..\)\(..\)/\2\3\1/g'
051608

# 3  
Old 06-04-2008
Quote:
Originally Posted by mondrar
The command below is getting me the output I need.....
Any ideas...
Please provide sample data.
# 4  
Old 06-05-2008
Thanks, that works, but what I really want to do is reformat the date in its current position, and leave all the text around it the same.

Is this possible, or am I confusing.
# 5  
Old 06-05-2008
Code:
 echo '900018732 00004961200200805160000000073719'| sed -e 's/\(.*\)20\(08\)\(....\)\(.*\)/\1\3\2\4/g'

# 6  
Old 06-05-2008
I was able to get it done, the long way. Yes, I know, it looks funny.

awk -F"," '{ if ($6 = 475) print $1 "," "@@"$3 "," $6 "," $10 "," $8}' ${DIR1}${INFILE} | sed -e 's/.*\(200.\{5\}\)00000000.*/\1/g' -e 's/^..\(..\)\(..\)\(..\)/\2\3\1/g' | sed -e 's/@@1//g' | sed -e 's/\.//g' | awk -F"," ' { print $2 " " "0000" $4 "0" $1 "00000000" $5}' > ${DIR2}${TPRFILE}
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reformat awk output

I need to rearrange the output but i am unable to arrange it to match the format. In the output i need NAME=\"To in the column . Bash: #!/bin/bash cd /cygdrive/c/output/a cat *.txt > output.txt i=/cygdrive/c/output/a/output.csv #echo "NE_Name, Source, Destination, OSPF_AREA_ID"... (4 Replies)
Discussion started by: adgjmpt
4 Replies

2. Shell Programming and Scripting

awk reformat file

Hello: When I tried a perl-oneliner to re-format fasta file. infile.fasta >YAL069W-1.334 Putative promoter CCACACCACACCCACACACC ACACCACACCCACACACACA ACAGCCCTAATCTAACCC >YAL068C-7235.2170 Putative ABC sequence TACGAGAATAATTT ACGTAAATGAAGTT TATATATAAA >gi|31044174|gb|AY143560.1|... (15 Replies)
Discussion started by: yifangt
15 Replies

3. Shell Programming and Scripting

awk to reformat text

I have this input and want output like below, how can I achieve that through awk: Input: CAT1 FRY-01 CAT1 FRY-04 CAT1 DRY-03 CAT1 FRY-02 CAT1 DRY-04 CAT2 FRY-03 CAT2 FRY-02 CAT2 DRY-01 FAT3 DRY-12 FAT3 FRY-06 Output: category CAT1 item FRY-01 (7 Replies)
Discussion started by: aydj
7 Replies

4. Shell Programming and Scripting

need awk or sed help to reformat output

We have the following output: server1_J00_data_20120711122243 server1_J00_igs_20120711122243 server1_J00_j2ee_20120711122243 server1_J00_sec_20120711122243 server1_J00_data_20120711131819 server1_J00_igs_20120711131819 server1_J00_j2ee_20120711131819 server2_J00_data_20120711122245... (10 Replies)
Discussion started by: ux4me
10 Replies

5. Shell Programming and Scripting

sed/awk date range?

Hi, I am trying to grep out a date range in an access log file. I defined the date like so; DATE1=$(date --date '1 hour ago' '+%m/%d/%y:%H:%M:%S') DATE2=$(date '+%m/%d/%y:%H:%M:%S') Then I just used cat to get the hits to the url into a results.txt; touch /tmp/results.txt cat... (7 Replies)
Discussion started by: Epx998
7 Replies

6. Shell Programming and Scripting

awk to reformat a text file

I am definitely not an expert with awk, and I want to reformat a text file like the following. This is probably a very easy one for an expert out there. I would like to keep the lines in the same order, but move the heading to only be listed once above the lines. This is what the text file... (7 Replies)
Discussion started by: linux4life
7 Replies

7. Shell Programming and Scripting

reformat date from istat

I would like to determine if a file is older than a particular date. I found that istat will let me see the date and time of a file older than a year, but I need to change the format. Could anyone help me reformat the following date to a variable (a one liner would be great). Output from istat -... (1 Reply)
Discussion started by: oldman2
1 Replies

8. Shell Programming and Scripting

Separate date timestamp use awk or sed command ?

Hi, I have logfile like this : Actually the format is date format : yyyymmddHHMMSS and i want the log become this format yyyy-mm-dd HH:MM:SS for example 2009-07-19 11:46:52 Can somebody help me ? Thanks in advance (3 Replies)
Discussion started by: justbow
3 Replies

9. Shell Programming and Scripting

help reformat data with awk

I am trying to write an awk program to reformat a data table and convert the date to julian time. I have all the individual steps working, but I am having some issues joing them into one program. Can anyone help me out? Here is my code so far: # This is an awk program to convert the dates from... (4 Replies)
Discussion started by: climbak
4 Replies

10. UNIX for Dummies Questions & Answers

Date Reformat

Hello, I have a .CSV file with 10+ datetime columns. The way the data is stored in these columns are - 4/4/2006 3:45:30 PM I want the single digits to be left padded with a zero so the above looks like 04/04/2006 03:45:30 PM As the dates and times are different throughout the file... (2 Replies)
Discussion started by: F-1
2 Replies
Login or Register to Ask a Question