{"id":115,"date":"2013-11-01T18:40:29","date_gmt":"2013-11-01T22:40:29","guid":{"rendered":"http:\/\/netapp.tynsoe.org\/wordpress\/?p=115"},"modified":"2013-11-01T18:40:29","modified_gmt":"2013-11-01T22:40:29","slug":"format-snapshots","status":"publish","type":"post","link":"https:\/\/ybontap.tynsoe.org\/?p=115","title":{"rendered":"Format a list of snapshots coming from a controller"},"content":{"rendered":"<p>Part of my job is to analyze different data from my customer&rsquo;s systems and dozen times a day I have to parse and transform regular output from Data ONTAP systems to more organized format, suitable for an Excel spreadsheet for example.<\/p>\n<p>This time I needed a list of \u00a0snapshots in a system.<\/p>\n<p><!--more-->The thing is that Data ONTAP returns in something like this :<\/p>\n<pre>yann$ ssh root@10.78.3.1 snap list -n\nVolume vol0\nworking...\n\nNo snapshots exist.\n\nVolume vol_01102013_135658\nworking...\n\ndate          name\n------------  --------\nNov 01 18:17  nightly.0      \nOct 31 12:51  nightly.1      \nOct 29 20:00  hourly.0       \nOct 25 16:00  hourly.1       \nOct 22 20:00  hourly.2       \nOct 22 17:03  hourly.3       \nOct 21 20:43  hourly.4       \nOct 21 16:00  hourly.5       \n\nVolume datastore3\nworking...\n\ndate          name\n------------  --------\nNov 01 18:17  nightly.0      \nOct 31 12:51  nightly.1      \nOct 29 20:00  hourly.0       \nOct 25 16:00  hourly.1       \nOct 22 20:00  hourly.2       \nOct 22 17:03  hourly.3       \nOct 21 20:43  hourly.4       \nOct 21 16:00  hourly.5       \n\nVolume data\nworking...\n\ndate          name\n------------  --------\nNov 01 18:17  nightly.0      \nOct 31 12:51  nightly.1      \nOct 29 20:00  hourly.0       \nOct 25 16:00  hourly.1       \nOct 22 20:00  hourly.2       \nOct 22 17:03  hourly.3       \nOct 21 20:43  hourly.4       \nOct 21 16:00  hourly.5       \nSep 24 08:59  vs1(4079432741)_data.1 (snapmirror)<\/pre>\n<p>So I spent an hour working on a <strong>sed<\/strong> command that would reformat this in a suitable copy\/paste-able text for Excel, and here is the result :<\/p>\n<pre>ssh root@10.78.3.1 snap list -n|tr -d '\\r' | <strong>sed -n -E '{\/^Volume \/{N;N;N;s\/\\n\/ \/g;s\/.*Volume ([^ ]*).*\/\\1\/;h;};\/^---\/,\/^$\/{\/^---\/d;\/^$\/d;G;s\/(.*) (..:..)  (.*)\\n(.*)\/\\4      \\1      \\2      \\3\/g;p;};}'<\/strong><\/pre>\n<p>Kinda crazy right ? I love sed, but sometimes you just have to empty your brain and let the inner geek in you take over.\u00a0Note that I couldn&rsquo;t reproduce in the blog the \u00ab\u00a0tab\u00a0\u00bb characters between \u00ab\u00a0\\4 \\1 \\2 \\3\u00a0\u00bb, to do this on a Mac OS X Terminal, you must type Ctrl-V then the \u00ab\u00a0tab\u00a0\u00bb key.<\/p>\n<p>Here is a sample output :<\/p>\n<pre>vol_01102013_135658\tNov 01\t18:17\tnightly.0      \nvol_01102013_135658\tOct 31\t12:51\tnightly.1      \nvol_01102013_135658\tOct 29\t20:00\thourly.0       \nvol_01102013_135658\tOct 25\t16:00\thourly.1       \nvol_01102013_135658\tOct 22\t20:00\thourly.2       \nvol_01102013_135658\tOct 22\t17:03\thourly.3       \nvol_01102013_135658\tOct 21\t20:43\thourly.4       \nvol_01102013_135658\tOct 21\t16:00\thourly.5       \ndatastore3\tNov 01\t18:17\tnightly.0      \ndatastore3\tOct 31\t12:51\tnightly.1      \ndatastore3\tOct 29\t20:00\thourly.0       \ndatastore3\tOct 25\t16:00\thourly.1       \ndatastore3\tOct 22\t20:00\thourly.2       \ndatastore3\tOct 22\t17:03\thourly.3       \ndatastore3\tOct 21\t20:43\thourly.4       \ndatastore3\tOct 21\t16:00\thourly.5       \ndata\tNov 01\t18:17\tnightly.0      \ndata\tOct 31\t12:51\tnightly.1      \ndata\tOct 29\t20:00\thourly.0       \ndata\tOct 25\t16:00\thourly.1       \ndata\tOct 22\t20:00\thourly.2       \ndata\tOct 22\t17:03\thourly.3       \ndata\tOct 21\t20:43\thourly.4       \ndata\tOct 21\t16:00\thourly.5       \ndata\tSep 24\t08:59\tvs1(4079432741)_data.1 (snapmirror)<\/pre>\n<p>You can paste this right into Excel :<\/p>\n<p><a href=\"http:\/\/netapp.tynsoe.org\/wordpress\/wp-content\/uploads\/2013\/11\/Capture_d_\u00e9cran_01_11_2013_18_34.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-116\" alt=\"snapshot list in Excel\" src=\"http:\/\/netapp.tynsoe.org\/wordpress\/wp-content\/uploads\/2013\/11\/Capture_d_\u00e9cran_01_11_2013_18_34.png\" width=\"504\" height=\"388\" \/><\/a><\/p>\n<p>It might not be perfect, text parsing is usually a delicate and sensible matter, but it is good enough for what I had to do and I thought it was worth sharing.<\/p>\n<p>Most users would use OnCommand Unified Manager to create a report, that&rsquo;s way easier ! But sometimes you just don&rsquo;t have access to it or it is quicker to get to an ssh connection.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Part of my job is to analyze different data from my customer&rsquo;s systems and dozen times a day I have to parse and transform regular output from Data ONTAP systems to more organized format, suitable for an Excel spreadsheet for example. This time I needed a list of \u00a0snapshots in a system.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[24,26],"_links":{"self":[{"href":"https:\/\/ybontap.tynsoe.org\/index.php?rest_route=\/wp\/v2\/posts\/115"}],"collection":[{"href":"https:\/\/ybontap.tynsoe.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ybontap.tynsoe.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ybontap.tynsoe.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ybontap.tynsoe.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=115"}],"version-history":[{"count":0,"href":"https:\/\/ybontap.tynsoe.org\/index.php?rest_route=\/wp\/v2\/posts\/115\/revisions"}],"wp:attachment":[{"href":"https:\/\/ybontap.tynsoe.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ybontap.tynsoe.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ybontap.tynsoe.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}