system
1
Hi guys,
I have a text file with lots of lines like this:
MCOGT23R27815 27/07/07 27/05/09
SO733AM0235 30/11/07 30/11/10
NL123403N 04/03/08 04/03/11
0747AM7474 04/04/08 04/04/11
I want to change each line so the date format looks like this:
MCOGT23R27815 07/07/27 09/05/27
SO733AM0235 07/11/30 10/11/30
NL123403N 08/03/04 11/03/04
0747AM7474 08/04/04 11/04/04
Thanks..
note:this is on a Solaris10 system
$
$ cat -n f7
1 MCOGT23R27815 27/07/07 27/05/09
2 SO733AM0235 30/11/07 30/11/10
3 NL123403N 04/03/08 04/03/11
4 0747AM7474 04/04/08 04/04/11
$
$ perl -lne 'chomp; @x=split/[ \/]/; print "$x[0] $x[3]/$x[2]/$x[1] $x[6]/$x[5]/$x[4]"' f7
MCOGT23R27815 07/07/27 09/05/27
SO733AM0235 07/11/30 10/11/30
NL123403N 08/03/04 11/03/04
0747AM7474 08/04/04 11/04/04
$
tyler_durden
system
4
Thanks for that.
One thing I forgot to mention is that the delimiter is not a space, it is a tab
drewk
5
perl -ple 's|(^\S+\s+)(\d{2})/(\d{2})/(\d{2}\s+)(\d{2})/(\d{2})/(\d{2})|\1\3/\2/\4\6/\5/\7|;' yourfile
For a tab:
perl -ple 's|(^\S+\t)(\d{2})/(\d{2})/(\d{2}\t)(\d{2})/(\d{2})/(\d{2})|\1\3/\2/\4\6/\5/\7|;' yourfile
system
6
Thanks for the help guys, I have it working in my script now.
awk -F "\t|\/" '{printf "%s\t%s\/%s\/%s\t%s\/%s\/%s\n",$1,$4,$3,$2,$7,$6,$5}' urfile
The whitespace in the following command is a literal tab inserted by typing control-v control-i or control-v <tab>
sed 's|\(..\)/\(..\)/\(..\) \(..\)/\(..\)/\(..\)$|\3/\2/\1 \6/\5/\4|' file
Regards,
Alister