0
0
Linux CLIscripting~10 mins

stdin redirection (<) in Linux CLI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read input from a file named 'input.txt' using stdin redirection.

Linux CLI
cat [1]
Drag options to blanks, or click blank then click option'
A< input.txt
B> input.txt
Cinput.txt
D>> input.txt
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' or '>>' which redirect output instead of input.
Just writing the filename without '<' does not redirect stdin.
2fill in blank
medium

Complete the command to count the number of lines in 'data.txt' using stdin redirection.

Linux CLI
wc -l [1]
Drag options to blanks, or click blank then click option'
A>> data.txt
Bdata.txt
C> data.txt
D< data.txt
Attempts:
3 left
💡 Hint
Common Mistakes
Using the filename without '<' which makes 'wc' treat it as an argument.
Using '>' or '>>' which redirect output, not input.
3fill in blank
hard

Fix the error in the command to sort the contents of 'list.txt' using stdin redirection.

Linux CLI
sort [1]
Drag options to blanks, or click blank then click option'
Alist.txt
B> list.txt
C< list.txt
D>> list.txt
Attempts:
3 left
💡 Hint
Common Mistakes
Using the filename without '<' which makes 'sort' treat it as an argument.
Using '>' or '>>' which redirect output and overwrite the file.
4fill in blank
hard

Fill both blanks to filter lines containing 'error' from 'log.txt' using stdin redirection and grep.

Linux CLI
grep [1] [2]
Drag options to blanks, or click blank then click option'
A"error"
B< log.txt
Clog.txt
D-i
Attempts:
3 left
💡 Hint
Common Mistakes
Using the filename as an argument instead of redirecting input.
Forgetting to quote the search pattern.
5fill in blank
hard

Fill all three blanks to print words longer than 5 letters from 'words.txt' using stdin redirection and awk (assuming one word per line).

Linux CLI
awk '[1] [2]' [3]
Drag options to blanks, or click blank then click option'
Alength($0) > 5
B< words.txt
C{print $0}
D> words.txt
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' for input redirection.
Omitting the print action in awk.
Not quoting the awk script properly.