Exam EX200 All QuestionsBrowse all questions from this 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.

    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
airphreak

grep abcde /etc/testfile > /tmp/testfile

adolfoale

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

eid

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

MELO225

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

Velda

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!

Bittercampari

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

thomasstate

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

ertgrty

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

Rahul95

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

techzideas

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

ktd971

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

ptmude

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