Pages: [1]   Go Down
  Print  
Author Topic: How to fix sequences in Numbers data by using a text editor  (Read 170 times)
HCK
Global Moderator
Hero Member
*****
Posts: 79425



« on: March 18, 2022, 04:05:13 pm »

How to fix sequences in Numbers data by using a text editor

<div id="link_wrapped_content">
<body><section class="wp-block-bigbite-multi-title"><div class="container"></div></section><p>You can use Apple&rsquo;s Numbers app for sophisticated spreadsheet work. But where it falls short&mdash;as does Microsoft Excel&mdash;is at cleaning up data that&rsquo;s in the spreadsheet. Where Microsoft Word lets you use patterns to match and replace values, you can&rsquo;t make that happen in Numbers, Excel, or Pages.</p>



<p>This can come up when you have dates, numbers, or currency values formatted in different ways that are imported or pasted into Numbers. Numbers will correct many kinds of standard formatting when typed in, but the same data may remain in its original, varied form when pasted in or when you open a CSV (comma-separated value) file, a common export format from other software and from websites.</p>



<p>You see this most frequently with names, where you receive a list formatted in one fashion&mdash;like &ldquo;last name, first name&rdquo;&mdash;and you want it another. Or each part of the data you have formats the name in different ways. One might split first, last, and middle initial into three fields. What you want, however, is&nbsp;normalized&nbsp;data&mdash;entries that are structured identically to allow them to be sorted, visually scanned, and organized in other ways.</p>



<p>There&rsquo;s a remarkably simple solution that costs nothing and might save a lot of manual re-entry and editing. Numbers lets you copy the contents of any number of cells and then paste them into a text editor. As long as you retain tabs and hard returns while editing, you can fix up what you pasted in the text editor, copy the revised data, and paste it over the exact area you copied from in Numbers.</p>



<p>I rely on&nbsp;<a href="https://go.redirectingat.com/?id=111346X1569486&amp;url=https://www.barebones.com/&amp;xcust=1-1-619953-1-0-0&amp;sref=https://www.macworld.com/feed" rel="nofollow">BBEdit[/url]&nbsp;to perform advanced wildcard matches called &ldquo;regular expression patching matching&rdquo; (regexp, for short) and to replace data with matched elements. Some apps support wildcards, where you drop in special characters or sequences to match parts of text, like any number (0 to 9) or a full sentence, defined by being between periods and other ending punctuation. Regexp is sophisticated, almost a simple programming language. Elements you match in a search can be grouped so that you can rearrange them as part of a text replacement. BBEdit labels the find part Grep after a Unix version of regexp. (The free version of BBEdit has all the features you need. Download the standard version and install it, and you have access to all features during a 30-day trial. When the trial ends, the app&nbsp;<a href="https://go.redirectingat.com/?id=111346X1569486&amp;url=https://www.barebones.com/products/bbedit/comparison.html&amp;xcust=1-1-619953-1-0-0&amp;sref=https://www.macworld.com/feed" rel="nofollow">&ldquo;downgrades&rdquo; to a more limited feature set[/url]&nbsp;that includes all the find-and-replace options required in this article.)</p>



<p>For instance, say you have data that lists names in the following way:</p>



<p><code>Jane Doe</code>&nbsp;(first and last in one field)&nbsp;<code>Jane</code>&nbsp;and&nbsp;<code>Doe</code>&nbsp;(first and last in separate fields)&nbsp;<code>Doe, Jane</code>&nbsp;(last name first, a comma, and then the first name)</p>



<p>For formatting and spreadsheet purposes, you decide you want all names divided into a first name and last name field, so you can sort by last name, but use the first name separately when exporting to an email list program.</p>



<p>First, make sure you have two adjacent fields in Numbers for first and last name. If you have a single &ldquo;full name&rdquo; field, select a cell in that field and press Option-right arrow to add a column after that name column. Re-label your name columns First Name and Last Name for clarity.</p>



<p>Next, copy the data by dragging a selection, either around the contents of a single field or both fields if you have a mixed set of data.</p>



<p>Now, paste into BBEdit. You&rsquo;ll see that each field is separated on a line by a tab. (If you want to view tabs, spaces, returns, and other characters, choose&nbsp;View &gt; Text Display &gt; Show Invisibles.)</p>



<p>You can compose your find/replace values to fix the data. Choose&nbsp;Search &gt; Find&nbsp;and check the Grep box to enable regexp. To fix all the&nbsp;<code>Doe, Jane</code>&nbsp;by putting them into two fields in the right order, you would use this search:</p>



<p><code>^(.*?), (.*)$</code></p>



<p>That pattern means: match from the start of the line (<code>^</code>), find all the text until the first comma (<code>(.*?)</code>) and group that to use in a replacement line; then find a command and space, and then make a second group of all the text (<code>(.*)</code>) to the end of the line (<code>$</code>).</p>



<p>In the Replace field, you would enter:</p>



<p><code>\2\t\1</code></p>



<p>Much simpler! That says, take the second grouping from the Find pattern (<code>\2</code>), follow it with a tab (<code>\t</code>), and then with the first grouping (<code>\1</code>).&nbsp;<code>Doe, Jane</code>&nbsp;becomes&nbsp;<code>Jane[tab]Doe</code>.</p>



<p>You can click Replace All if that pattern is isolated or the entire set of names. Or you can select a range of text in BBEdit and check &ldquo;Selected text only&rdquo; in the Find dialog before clicking Replace All.</p>



<p><strong>Warning:</strong>&nbsp;Make a copy before moving back to Numbers: if you have more rows or columns in your copied selection than what you started with or intend to fill, Numbers allows a paste to overwrite your other data.</p>



<p>Once all the data has been reformatted as you like, select it in BBEdit, copy it, and then in Numbers, select the starting cell that you want to paste into. The pasted rows will proceed downwards, and tabs will be converted to past into column cells to the right.</p>



<p>In one recent import, I had a very small change to make that was still beyond Numbers capability: dates and times were formatted as&nbsp;<code>2019/10/28, 22:51</code>, and Numbers doesn&rsquo;t recognize the comma as part of a datestamp. I could have round-tripped the data through BBEdit for a simple find of the comma and replaced it with nothing. But it&rsquo;s a simpler case to illustrate, as you can see in the figure below.</p>


<div class="extendedBlock-wrapper block-coreImage undefined"><figure class="wp-block-image size-large"><img loading="lazy" src="https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?w=1200" alt="" class="wp-image-619958" srcset="https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?quality=50&amp;strip=all 2152w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?resize=300%2C166&amp;quality=50&amp;strip=all 300w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?resize=768%2C425&amp;quality=50&amp;strip=all 768w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?resize=1200%2C665&amp;quality=50&amp;strip=all 1200w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?resize=1536%2C851&amp;quality=50&amp;strip=all 1536w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?resize=2048%2C1134&amp;quality=50&amp;strip=all 2048w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?resize=150%2C84&amp;quality=50&amp;strip=all 150w" width="1200" height="665" sizes="(max-width: 1200px) 100vw, 1200px" /><figcaption>Top row: Starting with the wrong format (a comma between date and time), use BBEdit&rsquo;s find-and-replace feature to match a pattern and fix it. Bottom row: Paste the revised data in and use Numbers&rsquo;s Data Format options to have it appear as you like. If it reformats, you know the data is structured properly for sorting.</figcaption></figure></div>



<p>Consult BBEdit&lsquo;s manual for more details on regexp. The developer, Bare Bones, offers an exhaustive explanation. But you can often find the specific recipe you need through an Internet search engine: type in &ldquo;regexp&rdquo; and what you&rsquo;re trying to do, and someone has usually already solved the problem. Standard regexp works within BBEdit&rsquo;s Find feature.</p>



<p>Within the 30-day BBEdit full trial or with a paid copy of the app, you can also test your patterns using the software&rsquo;s Pattern Playground&mdash;read&nbsp;<a href="https://go.redirectingat.com/?id=111346X1569486&amp;url=https://www.barebones.com/support/technotes/PatternPlaygrounds.html&amp;xcust=1-1-619953-1-0-0&amp;sref=https://www.macworld.com/feed" rel="nofollow">Bare Bones&rsquo;s documentation[/url]&nbsp;and&nbsp;<a href="https://go.redirectingat.com/?id=111346X1569486&amp;url=https://apps.apple.com/us/story/id1485320067&amp;xcust=1-1-619953-1-0-0&amp;sref=https://www.macworld.com/feed" rel="nofollow">this brief Apple write-up[/url].</p>


<div class="extendedBlock-wrapper block-coreImage undefined"><figure class="wp-block-image size-large"><img loading="lazy" src="https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-bbedit-playground-bordered.png?w=1200" alt="" class="wp-image-619961" srcset="https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-bbedit-playground-bordered.png?quality=50&amp;strip=all 1682w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-bbedit-playground-bordered.png?resize=300%2C269&amp;quality=50&amp;strip=all 300w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-bbedit-playground-bordered.png?resize=768%2C688&amp;quality=50&amp;strip=all 768w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-bbedit-playground-bordered.png?resize=1200%2C1074&amp;quality=50&amp;strip=all 1200w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-bbedit-playground-bordered.png?resize=1536%2C1375&amp;quality=50&amp;strip=all 1536w" width="1200" height="1074" sizes="(max-width: 1200px) 100vw, 1200px" /><figcaption>Pattern Playground lets you test our patterns and see live results. It can help you compose the right query.</figcaption></figure></div>



<h2 id="ask-mac-911">Ask Mac 911</h2>



<p>We&rsquo;ve compiled a list of the questions we get asked most frequently, along with answers and links to columns:&nbsp;read our super FAQ&nbsp;to see if your question is covered. If not, we&rsquo;re always looking for new problems to solve! Email yours to&nbsp;[email]mac911@macworld.com[/email], including screen captures as appropriate and whether you want your full name used. Not every question will be answered, we don&rsquo;t reply to email, and we cannot provide direct troubleshooting advice.</p>
</body></div>

Source: How to fix sequences in Numbers data by using a text editor
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: