Sort by

recency

|

137 Discussions

|

  • + 0 comments

    Does anyone know why the test case 2 if failing for below code:?

    while read -r line; do

    echo "${line:2:1}"
    

    done

  • + 0 comments

    cut -c3

    echo "hello" |cut -c3

    output = l

    cut is a command-line tool used to extract sections from each line of input — by bytes, characters, or fields.

  • + 0 comments
    1. Using cut Command: echo "$line" | cut -c3 Best For: Simple, single-character extraction. Limitation: Only handles one character at a time.
    2. Using Bash String Slicing Command: echo "${line:2:1}" Best For: Efficient, direct slicing of strings. Limitation: Fails on short or empty lines.
    3. Using awk Command: echo "Extra open brace or missing close brace0, 3, 1)}' Best For: More complex extraction with flexibility. Limitation: Overhead for simple tasks.
    4. Using while read Loop Command: while read line; do echo "${line:2:1}"; done Best For: Iterating over multiple lines. Limitation: Fails if lines are too short
  • + 0 comments

    Simplese cod e for bigners

    while read r
    do 
    echo "$r" | cut -c3
    done
    
  • + 0 comments

    read n for i in [1..toprint" | cut -c 3 done