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!

sed challenging... 1

Status
Not open for further replies.

hokky

Technical User
Nov 9, 2006
170
AU
Hi guys,

I just need to ask how to change the second column from dot delimiter using sed.

ie, data :

my home.1000.change

becomes

my home.90.change

Thanks guys
 
Hi

Code:
[gray]# just to contain the required counting to 2[/gray]

sed 's/[^.]\+\./90./2' /input/file

[gray]# or in this case there would be the same[/gray]

sed 's/\.[^.]\+/.90/' /input/file

[gray]# or[/gray]

sed 's/\.[^.]\+\./.90./' /input/file

Feherke.
 
Another way with awk:
awk 'BEGIN{FS=OFS="."}{$2=90;print}' /path/to/input

Yet another (legacy) sed method:
sed 's!\([^.]*\)\.[^.]*\.!\1.90.!' /path/to/input

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks feherke,

1 more question :
what about if I want to delete the line that the second column contain 1000, Thanks.
 
Sorry feherke,

sometimes they contain in 7th column as well, I tried this doesn't work

sed '/^^^^^^[^.]\+\.1000\./d' /input/file

Cheers,
 
Hi

Let us try to learn from PHV :
Code:
sed '/^[red][^.][/red][^.][red]*[/red]\.1000\./d' /input/file
Or just modify PHV's more portable [tt]awk[/tt] code :
Code:
awk 'BEGIN{FS=OFS="."}[red]$2!=1000{[/red]print}' /path/to/input

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top