how to enclose the first 3 digits with brackets in unix shell?

Home Forums Technical Discussions Unix how to enclose the first 3 digits with brackets in unix shell?

This topic contains 0 replies, has 1 voice, and was last updated by  Vinoth Sekar 4 years, 11 months ago.

  • Author
    Posts
  • #479

    Vinoth Sekar
    Keymaster

    input file : cat inputfile

    0018902579089
    0018945782920
    0026474933939
    0016474849493
    0026474848484

    output required :

    (001)8902579089
    (001)8945782920
    (002)6474933939
    (001)6474849493
    (002)6474848484

    We can achieve this using sed command ,

    sed ‘s/[[:digit:]][[:digit:]][[:digit:]][[:digit:]]/(&)/g’ inputfile

You must be logged in to reply to this topic.