We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Using cut
Command: echo "$line" | cut -c3
Best For: Simple, single-character extraction.
Limitation: Only handles one character at a time.
Using Bash String Slicing
Command: echo "${line:2:1}"
Best For: Efficient, direct slicing of strings.
Limitation: Fails on short or empty lines.
Using awk
Command: echo "0, 3, 1)}'
Best For: More complex extraction with flexibility.
Limitation: Overhead for simple tasks.
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
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cut #1
You are viewing a single comment's thread. Return to all comments →