EX200 Exam QuestionsBrowse all questions from this exam

EX200 Exam - Question 6


SIMULATION -

Find the rows that contain abcde from file /etc/testfile, and write it to the file/tmp/testfile, and the sequence is requested as the same as /etc/testfile.

Show Answer
Correct Answer:

To find rows that contain 'abcde' in the file '/etc/testfile' and write them to '/tmp/testfile' while preserving the order, the correct command is: grep abcde /etc/testfile > /tmp/testfile. This command simply uses 'grep' to search for the string 'abcde' within each line of '/etc/testfile' and directs the output to '/tmp/testfile', ensuring the sequence is maintained.

Discussion

12 comments
Sign in to comment
airphreak
Dec 25, 2020

grep abcde /etc/testfile > /tmp/testfile

adolfoale
Jan 16, 2021

cat /etc/testfile | grep "abcde" > /tmp/testfile

eid
Dec 20, 2021

cat /etc/testfile | grep abcde > /tmp/testfile OR grep abcde /etc/testfile > /tmp/testfile

MELO225
Sep 21, 2021

cat /etc/tesfile | grep abcde > /tmp/testfile

Velda
Mar 10, 2023

There is no specified if the content of destination file can be replaced. So i suppose that it can.. in that case these commands are correct: cat /etc/testfile | grep abcde > /tmp/testfile OR grep abcde /etc/testfile > /tmp/testfile In case that content of destination file should not be replaced, following command will work: cat /etc/testfile | while read line; do echo $line | grep abcde | tee -a /tmp/testfile; done There is missing ";" in "correct answer" here, so the command from there will work if you will copy paste it but if you need to write it on your own, you must add the ";" or use bash script!

ptmude
Jan 12, 2022

grep abcde /etc/testfile | tee /tmp/testfile

ktd971
Jan 27, 2023

grep ^abcde$ /etc/testfile > /tmp/testfile

techzideas
Jan 31, 2023

grep -w "abcde" /etc/testfile >> /tmp/testfile

Rahul95
May 31, 2023

#touch /tmp/testfile - if file doesn't exists #grep abcde /etc/testfile > /tmp/testfile #cat /tmp/testfile - to verfy

ertgrty
Aug 21, 2023

#grep "abcde" /etc/testfile > /tmp/testfile

thomasstate
Nov 23, 2023

this is my error message after i executed the command grep abcde /etc/testfile > /tmp/testfil "grep : /etc/testfile: Is a directory"

Bittercampari
Feb 1, 2024

awk '/abcde/ {print}' /etc/testfile >> /tmp/testfile