Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assistance need understanding SED backreferences/grouping

Status
Not open for further replies.

YEPssss

Technical User
Mar 13, 2006
6
DK
I have a dataset consisting of

n = number
The numbers can vary from a big integer to a floting point number
[tt]
n1 n2 n3 n4 n5 n6
dd-mm-yy,##.##,###.##,##.##,####.##,####,####.##
[/tt]
First objective is to change the order of the date, so that the line would look like this after processing:

[tt]
n1 n2 n3 n4 n5 n6
yy-mm-dd,##.##,###.##,##.##,####.##,####,####.##
[/tt]

For educational reasons it would be fun to se how it would look if one would like to change the order of the numbers (but that's optional and "only" to enlighten me and others facinated of SED).
 
Wauuu that was a quick response feherke ... I'll check by putting it inside the place especially reserved for this line in my SED script :)

 
Excellent feherke :)
will save me valuable time that I can spend playing with SED for other purposes.

SED is a damn fine & quick little thingie for such purposes :)

Thanks again

Johan
 
Another useful tool (awk):
awk '
BEGIN{FS=OFS=","}{if(split($1,a,/-/)==3)$1=a[3]"-"a[2]"-"a[1];print}
' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

PHV

I've used awk before in the past for similar but fell over SED for things in the category.

None of you tried having fun grouping/moving the numbers around after the date or even before the date yet though ;-)

I'm just using this example to get a better grasp/idea of the SED semantics/logic :)

I'll try and time both solutions on a big sample :)
 
For me, awk will be much easier for fields reordering ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV

Yes you're right on that account, but at times lean and mean is cute too ;)

Johan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top