1

Guys, i have a question : write a shell program to select 5 to 10 lines of a file and copy them to another file.

i wrote an ans like this:
sed -n '5,10p' filename.txt >newfile.txt

but i dont think its an 1 line program aa it has 4 marks. so.. can you tell me the ANS OF SHELL PROGRAM OF ABOVE QUESTION? thanks in advance.

ps: i am a beginner in linux shell.

Comments
  • 2
    I'm not an expert on sed...but it its a one liner. But you can accomplish the same with awk.

    Check this thread https://stackoverflow.com/questions...
  • 0
    @phacus i agree with you.. btw i think that one liner ans works on normal terminal then why its asking me to write a shell program? ( according to question)
  • 0
    @AurthurM Assuming it's an assignment, maybe they want you to create a loop?

    EDIT: Check ShellCheck always..it's a life saver

    shellchecker.com
  • 1
    Oneliner is any script that can fit in one line. So it's basically.. Any script :)
    to make it more correct, the script parts should not be ; separated, i.e. every command linked to another via the pipeline.

    Your sed solution is perfect for the job imo. It has the least overhead compared to other possible solutions.
  • 0
    @netikras thank you :)
Add Comment