Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerRank Cut #3 problem solution

YASH PAL, 31 July 2024

In this HackerRank Cut #3 problem-solution Using cut, multiple items can be retrieved with the same command. For instance, to return multiple columns from a line, there are two basic needs:

  1. Multiple columns that are not contiguous
  2. Multiple columns that are contiguous

The following commands split a string on dots, then return columns 1 and 3, then columns 1 through 3. The -d flag specifies the delimiter and the -f flag specifies the column(s) to return. Note that the delimiter is added back in to the results.

echo 100.200.300.400 |cut -d ‘.’ -f 1,3

100.300

echo 100.200.300.400 |cut -d ‘.’ -f 1-3

100.200.300

Read the man pages for concise documentation.

Display a range of characters starting at the 2nd position of a string and ending at the 7th position (both positions included).

HackerRank Cut #3 problem-solution

Problem solution.

#!/bin/bash
while read line; do
  if [[ $line == "" ]]; then
    break;
  else
    echo $line | cut -c2-7
  fi
done

Second solution.

cut -c2-7

Third solution.

cut -c2-7 $1

coding problems linux shell

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes