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

前端 未结 14 2053
-上瘾入骨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

    Is this what your after?

    my $string = 'USCAGoleta9311734.5021-120.1287855805';
    
    my $first_two_chars = substr $string, 0, 2;
    

    ref: substr

提交回复
热议问题