Computer Science, asked by Hiteshi5596, 11 months ago

Write a command to redirect the lines which contains the word "birbal" from the file "sample.Txt" to the file "redirlines.Txt".

Answers

Answered by pavan78333
17

Answer:

Write a command to redirect the lines which contains the word "Birbal" from the file "sample.txt" to the file "redirlines.txt".

grep "Birbal" sample.txt>redirlines.txt

Explanation:

What I have tried

grep creates desired file2 but doesn't modify file1

grep 'bar' file1 > file2

sed -i modifies desired file1 but doesn't create file2

sed -i '/bar/d' file1

If I execute both commands one after another, I get desired result. But here I am looking for a single line command out of curiosity and to make a script more concise.

Answered by anvitanvar032
0

Answer:

The correct answer of this question is "sample.Txt" to the file "redirlines.Txt".

Explanation:

Given - The lines which contains the word "birbal" from the file "sample.Txt" to the file "redirlines.Txt".

To Find - Write a command to redirect the lines which contains the word "birbal" from the file "sample.Txt" to the file "redirlines.Txt".

Write a command to move the lines in the file "sample.txt" that include the word "Birbal" to the file "redirlines.txt."

grep creates desired file2 but doesn't modify file1

grep 'bar' file1 > file2

sed -i modifies desired file1 but doesn't create file2

sed -i '/bar/d' file1

I run both instructions in order and obtain the intended outcome. But, out of curiosity and to make a script more brief, I'm seeking for an one line command.

#SPJ2

Similar questions