Sed: massive conversion eras among random other text

Centos / Linux Bash

I have a log file in which there are a lot of text and epoch-making numbers all over the place. I want to replace all eras if they are in a readable date / time.

I would like to get this through sed, as this seems like a tool to work with. It seems I cannot get the replacement part of sed to actually analyze the variable (era) for the conversion.

An example of what I'm working with ...

echo "Some stuff 1346474454 And not working" \
| sed 's/1[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/'"`bpdbm -ctime \&`"'/g'
Some stuff 0 = Thu Jan  1 01:00:00 1970 And not working

The bpdbm ​​part converts the given epoch variable to a usable date. Like this..

bpdbm -ctime 1346474454
1346474454 = Sat Sep  1 05:40:54 2012

So, how do I get the element "found", which will understand the team. Like I can't seem to get it to work.

Any help would be wonderful. If there is another way, that would be cool ... but I suspect sed will be the fastest.

!

+5
2

, . sed & , . - , . Perl:

perl -pe 'if ( ($t) = /(1[0-9]+)/ ) { s/$t/localtime($t)/e }'
+7

GNU sed, :

_

Some stuff 1346474454 And not working

GNU sed /e, , bpdbm:

sed 's/(.*)(1[0-9]{9})(.*)/echo \1 $(bpdbm -ctime \2) \3/e' infile

coreutils date:

sed 's/(.*)(1[0-9]{9})(.*)/echo \1 $(date -d @\2) \3/e' infile

Some stuff Sat Sep 1 06:40:54 CEST 2012 And not working

, bpdbm:

sed 's/(.*)(1[0-9]{9})(.*)/echo "\1$(date -d @\2 +\"%a %b %_d %T %Y\")\3"/e' infile

Some stuff Sat Sep  1 06:40:54 2012 And not working

, , . , .

+1

All Articles