How to extract the first two characters of a string in shell scripting?

前端 未结 14 2051
-上瘾入骨i
-上瘾入骨i 2020-12-07 13:54

For example, given:

USCAGoleta9311734.5021-120.1287855805

I want to extract just:

US
14条回答
  •  自闭症患者
    2020-12-07 14:07

    easiest way is

    ${string:position:length}
    

    Where this extracts $length substring from $string at $position.

    This is a bash builtin so awk or sed is not required.

提交回复
热议问题