Search code examples
linuxbashunixstdout

Read the cat output with specific range of the letters


I digged the stackoverlow and Superuse but I couldn't find answer for my need.

I need to read the output with range of line.

cat try.txt

00aa00nnn0123 Just trying to know

I just want to read the line of range 1 to 13 f.e just this line

00aa00nnn0123

The file just has one line.

Maybe answer will be so simple but I really struggle with this.

Thanks


Solution

  • Using Bash (substring) parameter expansion syntax ${str:position:length}

    Read contents of try.txt into variable

    var=$(<try.txt)
    

    Now extract first 13 characters from variable

    echo "${var:0:13}"
    00aa00nnn0123