Title: How to fix sequences in Numbers data by using a text editor Post by: HCK 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’s Numbers app for sophisticated spreadsheet work. But where it falls short—as does Microsoft Excel—is at cleaning up data that’s in the spreadsheet. Where Microsoft Word lets you use patterns to match and replace values, you can’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—like “last name, first name”—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 normalized data—entries that are structured identically to allow them to be sorted, visually scanned, and organized in other ways.</p> <p>There’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 <a href="https://go.redirectingat.com/?id=111346X1569486&url=https://www.barebones.com/&xcust=1-1-619953-1-0-0&sref=https://www.macworld.com/feed" rel="nofollow">BBEdit[/url] to perform advanced wildcard matches called “regular expression patching matching” (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 <a href="https://go.redirectingat.com/?id=111346X1569486&url=https://www.barebones.com/products/bbedit/comparison.html&xcust=1-1-619953-1-0-0&sref=https://www.macworld.com/feed" rel="nofollow">“downgrades” to a more limited feature set[/url] 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> (first and last in one field) <code>Jane</code> and <code>Doe</code> (first and last in separate fields) <code>Doe, Jane</code> (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 “full name” 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’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 View > Text Display > Show Invisibles.)</p> <p>You can compose your find/replace values to fix the data. Choose Search > Find and check the Grep box to enable regexp. To fix all the <code>Doe, Jane</code> 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>). <code>Doe, Jane</code> becomes <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 “Selected text only” in the Find dialog before clicking Replace All.</p> <p><strong>Warning:</strong> 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 <code>2019/10/28, 22:51</code>, and Numbers doesn’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’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&strip=all 2152w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?resize=300%2C166&quality=50&strip=all 300w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?resize=768%2C425&quality=50&strip=all 768w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?resize=1200%2C665&quality=50&strip=all 1200w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?resize=1536%2C851&quality=50&strip=all 1536w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?resize=2048%2C1134&quality=50&strip=all 2048w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-numbers-bbedit-reformat.png?resize=150%2C84&quality=50&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’s find-and-replace feature to match a pattern and fix it. Bottom row: Paste the revised data in and use Numbers’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‘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 “regexp” and what you’re trying to do, and someone has usually already solved the problem. Standard regexp works within BBEdit’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’s Pattern Playground—read <a href="https://go.redirectingat.com/?id=111346X1569486&url=https://www.barebones.com/support/technotes/PatternPlaygrounds.html&xcust=1-1-619953-1-0-0&sref=https://www.macworld.com/feed" rel="nofollow">Bare Bones’s documentation[/url] and <a href="https://go.redirectingat.com/?id=111346X1569486&url=https://apps.apple.com/us/story/id1485320067&xcust=1-1-619953-1-0-0&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&strip=all 1682w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-bbedit-playground-bordered.png?resize=300%2C269&quality=50&strip=all 300w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-bbedit-playground-bordered.png?resize=768%2C688&quality=50&strip=all 768w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-bbedit-playground-bordered.png?resize=1200%2C1074&quality=50&strip=all 1200w, https://b2c-contenthub.com/wp-content/uploads/2022/03/mac911-bbedit-playground-bordered.png?resize=1536%2C1375&quality=50&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’ve compiled a list of the questions we get asked most frequently, along with answers and links to columns: read our super FAQ (http://www.macworld.com/article/3077986/os-x/your-top-questions-to-mac-911-and-some-answers.html) to see if your question is covered. If not, we’re always looking for new problems to solve! Email yours to mac911@macworld.com (http://mailto:mac911@macworld.com), including screen captures as appropriate and whether you want your full name used. Not every question will be answered, we don’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 (https://www.macworld.com/article/619953/fix-sequences-in-numbers-data.html) |