![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to sort a field in a file having date values | risshanth | Shell Programming and Scripting | 4 | 06-04-2008 02:03 AM |
| how to arrange 3 file to one using awk...? | penyu | Shell Programming and Scripting | 9 | 01-17-2008 01:26 AM |
| Compare dates in a field and print the latest date row | cvkishore | Shell Programming and Scripting | 1 | 08-04-2007 04:58 AM |
| handling date field | mgirinath | Shell Programming and Scripting | 3 | 04-03-2007 03:00 PM |
| re arrange the columns | ahmedwaseem2000 | Shell Programming and Scripting | 0 | 09-22-2005 11:51 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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 2|LAX|02/24/2006 13:12:35|sf49ers|30|M 3|OAK|02/25/2006 11:12:36|goraiders|27|F 4|PIT|02/25/2006 12:12:37|steeler|35|M Thanks . |
| Forum Sponsor | ||
|
|
|
|||
|
What was wrong with my code ??? it look right to me but it give me the error
datetime="`echo $3 | nawk '{n=split($1, da, "/"); print da[2]"/" da[3]"/20" da[1] " " $2}'`"; this is the error `(' is not expected. if datetime is work then I solve my problem . I test this and it works ??? echo '06/02/25 12:05:06' | nawk '{n=split($1, da, "/"); print da[2]"/" da[3]"/20" da[1] " " $2}' Please knock me where i made mistake . Thanks, |
|
|||
|
nawk 'BEGIN {FS="[ |/]"}
{ printf("%s|%s|%s/%s/%s %s",$1,$2,$4,$5,$3,$6); for(i=7;i<=NF;i++) { printf("|%s",$i); } printf "\n"; }' filename if you want to sort based on the date field, then append the following to end of above command. | sort -t "|" -k 3.3 |
|
|||
|
Oh, I would like to have the date field change as I want.
mgirinath, this one give me only the date mahendramahendr, this one give me the out put the same as b4. I want datetime field change from 06/02/25 11:12:36 to 02/25/2006 11:12:36 but my code got the error ? why syntax error is `(' is not expected |
|
|||
|
$ more tmp1
2|LAX|06/02/24 13:12:35|sf49ers|30|M 3|OAK|06/02/25 11:12:36|goraiders|27|F 1|SFO|06/02/24 12:12:34|hawkeye|35|M 4|PIT|06/02/25 12:12:37|steeler|35|M $ nawk 'BEGIN {FS="[ |/]"} { printf("%s|%s|%s/%s/%s %s",$1,$2,$4,$5,$3,$6); for(i=7;i<=NF;i++) { printf("|%s",$i); } printf "\n"; }' tmp1 2|LAX|02/24/06 13:12:35|sf49ers|30|M 3|OAK|02/25/06 11:12:36|goraiders|27|F 1|SFO|02/24/06 12:12:34|hawkeye|35|M 4|PIT|02/25/06 12:12:37|steeler|35|M You can clearly see the date format changing to MM/DD/YY... Is it not what you are looking for ?? what do you mean by same as b4 ? I think the format of your flat file is different than what you have posted if it is not working.... |
|
|||
|
Quote:
Code:
date=`echo "$3" | awk -F"/" '{ print $2"/"substr($3,1,2)"/20"$1 }'`
time=`echo "$3" | awk '{ print $2 }'`
echo $date" "$time
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|