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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Linux Shell
  3. Text Processing
  4. Middle of a Text File
  5. Discussions

Middle of a Text File

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 96 Discussions, By:

recency

Please Login in order to post a comment

  • ideepraj10
    2 months ago+ 0 comments
    while read line;
    do
    cat $file | sed -n '11,21p'
    done
    
    0|
    Permalink
  • kkCyberS
    2 months ago+ 0 comments

    1.

    head -22 | tail -11
    

    2.

    awk 'NR==12, NR==22 {print $0}'
    

    https://www.geeksforgeeks.org/awk-command-unixlinux-examples/

    3.

    sed -n '12,22p'
    

    https://www.gnu.org/software/sed/manual/sed.html

    1|
    Permalink
  • cahitbarkinozer
    5 months ago+ 0 comments
    while read lines; do
        echo $lines >> file.txt
    done
    (head -n 22 | tail -n 11) < file.txt
    
    0|
    Permalink
  • andreypomortsev
    6 months ago+ 0 comments
    sed -n '12,22p'
    

    This script uses the sed command to print out a range of lines from the input text. Here's what each part of the script does:

    sed is a Unix command-line utility for manipulating text. -n is an option that tells sed not to print out every line it processes. '12,22p' is a command that tells sed to print out only the lines between line 12 and line 22, inclusive. So, when you run the command sed -n '12,22p', sed reads in the input text, but only prints out lines 12 through 22.

    0|
    Permalink
  • florin_tanasa
    7 months ago+ 0 comments
    #!/bin/bash
    rm file.txt > stdout.tx 2> stderr.txt
    while read LINES;
    do
    echo $LINES >> file.txt
    done
    (head -n22 | tail -n11) < file.txt
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy