<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk/22126/index.php?action=history&amp;feed=atom&amp;title=Unix_answers</id>
	<title>Unix answers - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk/22126/index.php?action=history&amp;feed=atom&amp;title=Unix_answers"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22126/index.php?title=Unix_answers&amp;action=history"/>
	<updated>2026-05-16T04:01:13Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/22126/index.php?title=Unix_answers&amp;diff=214&amp;oldid=prev</id>
		<title>Mick at 14:46, 19 November 2025</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22126/index.php?title=Unix_answers&amp;diff=214&amp;oldid=prev"/>
		<updated>2025-11-19T14:46:29Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://teaching.healthtech.dtu.dk/22126/index.php?title=Unix_answers&amp;amp;diff=214&amp;amp;oldid=13&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Mick</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk/22126/index.php?title=Unix_answers&amp;diff=13&amp;oldid=prev</id>
		<title>WikiSysop: Created page with &quot; 1. Use a text editor to (nedit/gedit/komodo/textwrangler) to create a file mycommands.txt where you write all commands and observations you do in the following exercises. Use copy/paste to copy the commands. Note: There are more standard text editors than nedit, etc. Examples are emacs, xemacs, vi, vim, and pico. Make sure that we can easily see which exercise you attempt to solve.  2. First list the files in the directory.  &lt;pre&gt; ls &lt;/pre&gt;  3. Copy ex1.acc to myfile.ac...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk/22126/index.php?title=Unix_answers&amp;diff=13&amp;oldid=prev"/>
		<updated>2024-03-19T15:18:41Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; 1. Use a text editor to (nedit/gedit/komodo/textwrangler) to create a file mycommands.txt where you write all commands and observations you do in the following exercises. Use copy/paste to copy the commands. Note: There are more standard text editors than nedit, etc. Examples are emacs, xemacs, vi, vim, and pico. Make sure that we can easily see which exercise you attempt to solve.  2. First list the files in the directory.  &amp;lt;pre&amp;gt; ls &amp;lt;/pre&amp;gt;  3. Copy ex1.acc to myfile.ac...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
1. Use a text editor to (nedit/gedit/komodo/textwrangler) to create a file mycommands.txt where you write all commands and observations you do in the following exercises. Use copy/paste to copy the commands.&lt;br /&gt;
Note: There are more standard text editors than nedit, etc. Examples are emacs, xemacs, vi, vim, and pico.&lt;br /&gt;
Make sure that we can easily see which exercise you attempt to solve.&lt;br /&gt;
&lt;br /&gt;
2. First list the files in the directory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Copy ex1.acc to myfile.acc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cp ex1.acc myfile.acc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Look at the content of both files to ensure they are identical.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat ex1.acc &lt;br /&gt;
cat myfile.acc &lt;br /&gt;
paste  ex1.acc myfile.acc &lt;br /&gt;
diff  ex1.acc myfile.acc &lt;br /&gt;
md5sum  ex1.acc myfile.acc &lt;br /&gt;
sha256sum  ex1.acc myfile.acc &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5. Copy ex1.dat to myfile.acc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cp ex1.dat myfile.acc &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
6. Check that the content of myfile.acc changed.&lt;br /&gt;
&lt;br /&gt;
same as above&lt;br /&gt;
&lt;br /&gt;
7. Delete myfile.acc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm myfile.acc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
8. Make a directory test and move the three files to it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir test&lt;br /&gt;
&lt;br /&gt;
mv * test/&lt;br /&gt;
#or&lt;br /&gt;
mv ex1.acc test/&lt;br /&gt;
mv ex1.dat test/&lt;br /&gt;
mv orphans.sp test/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
9. Make a directory data and move the three files to that instead.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir data/&lt;br /&gt;
mv test/* data/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
10. Remove test directory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rmdir test/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
11. Change directory to data and confirm that you succeded. Go back to the home directory or work directory afterwards.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd data/&lt;br /&gt;
pwd&lt;br /&gt;
&lt;br /&gt;
cd -&lt;br /&gt;
#or&lt;br /&gt;
cd ~ &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
12. Make three new directories newtest - one inside the other, like a russian doll.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir newtest&lt;br /&gt;
cd newtest&lt;br /&gt;
mkdir newtest&lt;br /&gt;
cd newtest&lt;br /&gt;
mkdir newtest&lt;br /&gt;
cd newtest&lt;br /&gt;
#to visualize:&lt;br /&gt;
pwd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
13. Move the data directory to the innermost newtest directory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd ..&lt;br /&gt;
cd ..&lt;br /&gt;
cd ..&lt;br /&gt;
&lt;br /&gt;
#or&lt;br /&gt;
cd ../../..&lt;br /&gt;
&lt;br /&gt;
mv data/ newtest/newtest/newtest/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
14. Confirm that the three files are moved along with the data directory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls newtest/newtest/newtest/data/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
15. Copy the three files to your home (your top directory).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cp newtest/newtest/newtest/data/* .&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
16. Remove all newtest directories and data in the with a single command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm -vr newtest/&lt;br /&gt;
#v for verbose, fun to see what happens&lt;br /&gt;
#r for recursive&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
17. Count the lines in ex1.acc and ex1.dat.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wc -l ex1.*&lt;br /&gt;
#or&lt;br /&gt;
wc -l ex1.acc&lt;br /&gt;
wc -l ex1.dat&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
18. Concatenate ex1.acc and ex1.dat in the file ex1.tot, i.e. copy the content of two files into one new file. Verify that all gene IDs comes first followed by numerical data.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat ex1.acc ex1.dat &amp;gt; ex1.tot&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
19. Merge/Paste ex1.acc and ex1.dat together in ex1.tot, thus destroying the old file. Verify that corresponding gene IDs and numerical data are put on the same line. as the data.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
paste ex1.acc ex1.dat &amp;gt; ex1.tot&lt;br /&gt;
&lt;br /&gt;
head ex1.acc&lt;br /&gt;
head ex1.dat&lt;br /&gt;
head ex1.tot&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
tail ex1.acc&lt;br /&gt;
tail ex1.dat&lt;br /&gt;
tail ex1.tot&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: Some versions of MobaXterm has an unfortunate bug in the command neded. You still need to do the exercise but you can get the right result here for your use in the following exercises.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
20. Extract (cut) SwissProt ID and 3nd numerical data (column 1 and 5) from ex1.tot. Put results into a file ex1.res.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cut -f 1,5 ex1.tot &amp;gt; ex1.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
21. Find the 3 SwisProt ID&amp;#039;s in ex1.res which have the largest number(s) in column 2, i.e. the top 3 entries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sort -k2gr,2 ex1.res|head -3&lt;br /&gt;
#or &lt;br /&gt;
sort -k2nr,2 ex1.res|head -3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#be wary of the difference between -g and -n https://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html&lt;br /&gt;
&lt;br /&gt;
21. Find the lines (using grep) in orphans.sp which contain a GenBank accession number. There are 85, verify this. Note: An accession number is one or two capital letters and looks like this &amp;#039;AB000114.CDS.1&amp;#039;, the .CDS. part is kind of optional.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grep -c -E  &amp;quot;[A-Z]{2}[0-9]{5,6}&amp;quot; orphans.sp&lt;br /&gt;
#or&lt;br /&gt;
grep -c     &amp;quot;[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9]&amp;quot; orphans.sp&lt;br /&gt;
#or&lt;br /&gt;
grep      &amp;quot;[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9]&amp;quot; orphans.sp|wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
22. How many human genes with SwissProt IDs in orphans.sp exist ? How many of those are hypothetical ? (11) Note: A Swissprot ID looks like &amp;#039;PARG_HUMAN&amp;#039; or &amp;#039;TF1A_MOUSE&amp;#039;, with the gene being before the underscore and the organism after the underscore.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grep -c  &amp;quot;_HUMAN&amp;quot; orphans.sp&lt;br /&gt;
#207&lt;br /&gt;
grep   &amp;quot;_HUMAN&amp;quot; orphans.sp|grep -c HYPOTHETICAL &lt;br /&gt;
#11&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
23. How many genes belong to the rat, and how many of those are precursors ? &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grep    &amp;quot;_RAT&amp;quot; orphans.sp|wc -l &lt;br /&gt;
#51&lt;br /&gt;
grep    &amp;quot;_RAT&amp;quot; orphans.sp |grep PRECURSOR |wc -l &lt;br /&gt;
#9&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
24. From the file ex1.res find the lines with positive numbers and put then into ex1.pos. The lines with negative number go into ex1.neg.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat ex1.res  |grep &amp;quot;-&amp;quot; &amp;gt; ex1.neg&lt;br /&gt;
cat ex1.res  |grep -v &amp;quot;-&amp;quot; &amp;gt; ex1.pos&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
25. Write a shell script that solves exercise 19-24, with the exercises clearly separated in both the script and the output. The output should be explained. &amp;quot;42&amp;quot; is unclear, but &amp;quot;Number of genes: 42&amp;quot; is clear. This should be straight forward (but long), especially since you took notes (exercise 1).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
26. Write a shell script (which is simply just a list of unix commands in a file) that puts all the positive numbers in the file ex1.dat into a file ex1.pos2, and all the negative numbers into a file ex1.neg2. Column position does not matter. The script must clean up after itself, so if any temporary files are used, they must be deleted as the last action. Remember to put the date and a description of the files in the first lines of the resulting output files.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>