Header Ad

HackerRank Middle of a Text File problem solution

In this HackerRank Middle of a Text File problem solution, we need to display the lines (from line number 12 to 22, both inclusive) of a given text file.

Input Format

A text file

Output Format

Display the lines (from line number 12 to 22, both inclusive) for the input file.

HackerRank Middle of a Text File problem solution


Problem solution.

head -n 22 | tail -n +12


Second solution.

touch file
cat > file
head -n 22 file > file1
tail -n 11 file1


Third solution.

for ((i=1; i<=22; ++i)); do
    read
    if ((i >= 12)); then
        echo $REPLY
    fi
done


Post a Comment

0 Comments