-2
\$\begingroup\$

I had this homework assignment:

  1. Create on the desktop a folder with your name.
  2. Copy from your account [email protected] two files, "plik1.pdp" and "plik2.pdb".
  3. Combine them to make a new file, "plik3.pdb", but they have to be in special order. The second file should be first, and then the first one.
  4. Write down from the connected/combined "plik3.pdb" lines with "CA" to the new file "plik4.pdb".
  5. In this new file, change the lines 1-240 from "1.00" to "0.00".

The following code is my solution:

cd Desktop
mkdir "name"
cd "name"
scp [email protected]:/home/XYZ plik[12].pdb
cat plik2.pdb plik1.pdb > plik3.pdb
grep 'CA' plik3 > plik4
sed -i -n 1,240p -e 's/1\.00/0\.00' plik4

Is it ok? Did I do anything wrong?

\$\endgroup\$
2
  • 6
    \$\begingroup\$ Is it ok? Did you check whether it works as expected? \$\endgroup\$
    – Mast
    Commented Oct 12, 2015 at 21:35
  • \$\begingroup\$ What is XYZ? Is it not for real? I mean, just an example? In those times of Alphabet and xyz.xyz, I think it is a reasonable doubt. \$\endgroup\$
    – cpicanco
    Commented Oct 13, 2015 at 1:55

1 Answer 1

1
\$\begingroup\$

Overall it is close, but it won't work. Given that it's a homework assignment, you would possibly get points for trying, but if you ever intend to use bash scripting after school (and you should; it's very useful) do yourself a favor and set up a Linux test environment on your personal computer to play around with.

Only two things wrong that I see (though I didn't test it). In order of simplicity:

  1. You stopped including the filename extensions in your last two commands. plik3.pdp and plik3 refer to two different files; extensions are not considered in any special way in Linux and are simply part of the filename.
  2. Your scp command is wrong. I don't think it will do anything (just throw an error), but if it does anything it definitely won't be what you expect.

Try scp [email protected]:/home/XYZ/plik{1,2}.pdb ./

Note the added slash in the source name, and the inclusion of a target directory ./, which refers to the current working directory (in this case, Desktop/name).

By the way, the shell will expand the above to scp [email protected]:/home/XYZ/plik1.pdb [email protected]:/home/XYZ/plik2.pdb ./ Which gives you a hint on syntax if you need to copy multiple files that don't have the first part of the name in common.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ If you install vagrant and virtualbox, which are free and easily available for Mac, Windows and Linux, you can very easily set up a virtual machine running Linux. \$\endgroup\$
    – Wildcard
    Commented Oct 15, 2015 at 3:43
  • 1
    \$\begingroup\$ The OP also forgot the final / in the sed s/// command. \$\endgroup\$
    – cas
    Commented Oct 25, 2015 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.