Skip to content
Programmingoneonone
Programmingoneonone
  • 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
Programmingoneonone

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 solutions linux shell

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes