In this HackerRank Cut #5 problem solution we have given a tab-delimited file with several columns (tsv format) print the first three fields.
Input Format
A tab-separated file with lines of ASCII text only.
Constraints
1 <= N <= 100
2 <= C <= 100
(N is the number of lines of text in the input file and C is the number of columns of data in the file)
Output Format
The output should contain N lines. For each line in the input, print the first three fields.
Problem solution.
cut -f -3
Second solution.
while read line
do
cut -f-3 <<< "$line"
done
Third solution.
#!/bin/bash while read -r x do echo "$x" | cut -f1-3 done exit 0
0 Comments