• 0

Extracting select data from CSV file (one column)


Question

Have a CSV file w/ about 15 columns - when opened in spread sheet (also have couple of "CSV editor" prgms).

Want to take 1 of the columns (by what ever method), & get it into a text config file in another prgm.

When you look at any CSV file in a text editor, there are NO spaces after each comma & before next data (datum).

The syntax for the prgm (text file) I'm trying to enter the data into, shows no spaces to be used between each comma & next data. Just a command then data list, w/ each piece of data separated by commas, but no spaces. It appears when I enter the data (including spaces) in the other prgm's text file, it does NOT use it correctly. I'm * assuming * it's because of the spaces - but I'm no expert on this.

Everything I've tried w/ Open Office, Excell (older ver), the CVS editors, Notepad ++, always winds up putting a space after each comma - before next piece of data.

Even when I delete everything from the orig CVS file except the column I want, once opened in the spread sheets, then save it in .cvs format, then reopen it in something other than a spreadsheet (text editor, etc.), it either has no commas at all, or put spaces between data. In short, the spreadsheets aren't saving the edited files in the EXACT same CVS format (w/ no spaces) as the original CVS file.

Any ideas how to do it the way (I think) I need to do it, w/o introducing spaces? Thanks.

6 answers to this question

Recommended Posts

  • 0

You will need to craft a Regular Expression to match the data you need and to insert it into the desitnation file.

I haven't read this page, but it seems like it might be a good explaination on how to use RegEx in Notepad++

http://markantoniou.blogspot.com/2008/06/notepad-how-to-use-regular-expressions.html

  • 0

Thanks Frazell, took a quick look at the page linked. (It has links to more detailed pages on using regular expressions & examples).

Caught a bit about using "search & replace" in Notepad ++. It was talking about adding spaces, so figured might work in reverse - it did. For this, I didn't have to use a Regular Expression (which I know nothing about). Used Notepad++ "find & replace" function, to find all blank spaces followed by comma, & replace w/ just a comma. Worked fine.

Depending on which spreadsheet I copy one column into Notepad ++, each line in the data copied in to Notepad ++ may / may not have an actual comma (& space) before each value.

First had to use the Edit>Column Editor function to add a comma in front of each value (there was one value on each line, in column form). Put the cursor at the place where want to enter the comma (or what ever want to add).

But, as said, after that, when use "unwrap" in Notepad ++, there's a space between every comma & next value, which I had to remove.

Not sure why the spreadsheets aren't smart enough to (or don't) save BACK to a CSV format & eliminate spaces between commas & values - the same way orig CSV file was before the spread sheet opened it. Seems like would be very common use to open & edit a CSV file in a spread sheet, then save back to CSV format (without spaces) - to open / use in other prgms, instead of going through extra steps of eliminating the spaces. Maybe not - maybe most uses for edited / saved CSV files prefer spaces between separators? Very little experience w/ them.

Prgms like Excel, OO Calc do warn (to the effect): "this file (may?) contain content or formatting that can't be saved in text .CSV format..."

Odd that they just opened a CSV file that contained no spaces between separators, but when saving it back to .CSV, they put spaces between all separators??

  • 0

Interesting, jocaaa. I tried older ver of Excel (office 2000), but newest Open Office Calc. May well be operator error (ignorance), but saw nothing in options how to save the file, once edited in spread sheet(s), back to CSV file, whether to include / exclude spaces (or anything else).

When you opened an original CSV file (which assume contained no spaces) in Excel '07, did you do any editing before saving back to CSV (or maybe trying saving w/o doing editing)?

Maybe there are options / settings in Excell that specify about properties for saving in CSV format, that exclude spaces?

In your example, assuming when you opened it in Excel, it showed 3 cols & 2 rows in spread sheet. Then when saved back to CSV format file, & you looked at that saved file in a text editor, had no spaces?

  • 0

There were no editing at all, and yes, I checked it in text editor and hex editor - no (unwanted) spaces as you describe. I tried several scenarios - first to open an existing .csv file and export (save as) it to another .csv file, and to enter values manually in Excel and export them to .csv - no spaces in either case. In your case double check if you have string values in Excell cells without space characters.

  • 0

I can't find any thing about "string values w/o space characters" in options or help files of either Excell '00, or latest open office Calc.

But, think I see what you mean. The key part of my OP you overlooked was,

  Quote
Want to take 1 of the columns (by what ever method), & get it into a text config file in another prgm.

Yes, if I edit it down to 2 cols, then export to CSV, each value * in a row * has no spaces between commas / values.

But if save only ONE column to a CSV file, then try to manipulate it in text editor (like Notepad ++), & unwrap the rows, so it appears like a CSV file, THEN all values have a space between them.

When I open that saved CSV file w/ only 1 col left, in most editors, it initially shows up as 1 col, w/ 1 value in each row (go figure). But, there are obviously hidden spaces after each value, because when unwrap the col, it does separate each value w/ comma, but also has a space.

I'm assuming this is part of the formatting of a CSV file to specify when to make a new row (for multi row files). That was the problem I had - dealing w/ using only 1 col AND getting rid of the spaces between values.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • This is a common misnomer that Intel refuses to correct, E-Cores the E doesn't stand for efficiency in power (although they are more efficient than performance cores) but are actually "space efficient" which means they occupy much less space for same computational power thus allowing more of them in a footprint.
    • If you have top secret documents from the government or your company, you will not use a user cloud service. Pete Hegseth would like a word. I doubt that security fiasco stops at Signal. Stop being so stupid that you think that your useless information on your PC is as important as you think it is. This is just another crude way of saying it shouldn't matter if have nothing to hide. Not everyone wants to become a product, but you do you. If you cared about the content, you would not use these documents and photos on Android and iPhone phones because the telemetry there is 100,000% worse than on Windows 11. I love the telemetry comment. You cannot prove one way or another if it's better or worse on Windows vs. iOS or Android.
    • Minecraft's big graphics overhaul is now available by Taras Buria It is a big day for Minecraft fans. Mojang has released the long-anticipated graphics overhaul and a new content drop. The Chase the Skies update is now available in Minecraft on all supported platforms, while the Vibrant Visuals overhaul is currently available in Minecraft Bedrock Edition only (it is coming to Java Edition later). Mojang planned a visual update for Minecraft eight years ago, but the Super-Duper Graphics project was cancelled due to performance and other issues. Now, Mojang is ready to try again. This time, however, the update has been successfully delivered to gamers. The reworked graphics in Minecraft include directional lighting, volumetric fog, improved shadows, reflections, godrays, and a lot more. Previously, stuff like this required Minecraft RTX or third-party shaders, but now, the game has improved graphics natively. The update is available across many devices, and you do not need a high-end PC to run it. The upgrade is available on the following systems: Android with Adreno 640, Mali-G68, Mali-G77, Xclipse 530, and higher. iPhones and iPads with the A12 or M1 processor and higher. Any PC with DirectX 12 support. PlayStation 4 and PlayStation 5. Xbox One and Xbox Series X|S. You can enable Vibrant Visuals in display settings. Note that while the upgrade is compatible with many devices, performance still takes a hit. However, you can improve your experience by tweaking different parts of the visual overhaul in graphics settings. Another thing worth noting is that splitscreen multiplayer does not currently support Vibrant Visuals, just like worlds and texture packs. As for the Chase the Skies update, it introduces happy ghasts, new music disks, locator bar for players, environmental fog in the overworld, new background music, and all sorts of small gameplay changes, such as the ability to craft a saddle and a leade, horse taming with carrots, and more. You can read more about the latest Minecraft update in a post on the official website.
    • “We know Biden and Hunter and many in that administration profited tremendously from the support of Ukraine. Nobody talks about that.” Every single right wing talking head has been talking about that and Hunter’s laptop since 2022. Republicans could not even make the case that involved Joe through congressional oversight . ”We do not know what his true motives are other than what we see.” Maybe the way he behaves and talks should show you his true motives (not everything is hidden or a conspiracy). He is a lying bigot who cares about money and power.
  • Recent Achievements

    • Reacting Well
      Cole Multipass earned a badge
      Reacting Well
    • Reacting Well
      JLP earned a badge
      Reacting Well
    • Week One Done
      Rhydderch earned a badge
      Week One Done
    • Experienced
      dismuter went up a rank
      Experienced
    • One Month Later
      mevinyavin earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      693
    2. 2
      ATLien_0
      274
    3. 3
      Michael Scrip
      217
    4. 4
      +FloatingFatMan
      189
    5. 5
      Steven P.
      146
  • Tell a friend

    Love Neowin? Tell a friend!