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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

separate with "-" every 4 characters in long string

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL
hello,

example input lines in a file:

htrfskjfsfhssflk
weoiurweroiljask

desired output:

htrf-skjf-sfhs-sflk
weoi-urwe-roil-jask

thank you in advance for some short awk solution!

 


ok,thank you -- google already found it.

sed 's/..../&-/g;s/-$//'

awk '{for(i=1;i<=length($0);i+=4){printf("%s-",substr($0,i,4))}}'|awk '{sub(/-$/,"")};1'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top