LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-16-2019, 04:11 AM   #1
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,720

Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Question Quick way to convert spaces in text file to tabs to copy to spreadsheet?


Hi.

I have a file with dates and then weights (kg). They are separated by a space.

i.e.:
2019-08-01 68.7

I'd like to copy this long list to a spreadsheet once in a while to show a graph of my weight and other peoples weights. Is there a quick method to do this?

Thanks.
 
Old 08-16-2019, 04:15 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
tr, sed, awk, perl, python, ...

Start with the manpage for tr.
 
Old 08-16-2019, 04:24 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,864

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
Quote:
Originally Posted by linustalman View Post
Is there a quick method to do this?
The answer is: yes. You can also implement it easily in bash.
But from your side: Which language/tool do you prefer? What did you try so far? Where did you stuck?
 
Old 08-16-2019, 06:38 AM   #4
EmaRsk
Member
 
Registered: Mar 2006
Distribution: Mint, WSL Ubuntu
Posts: 134

Rep: Reputation: 32
Code:
tr " " "\t" <original_file >converted_file
or
Code:
sed "s/ /\t/" original_file >converted_file

Last edited by EmaRsk; 08-19-2019 at 02:07 PM.
 
1 members found this post helpful.
Old 08-16-2019, 06:55 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,715

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
Depends on spreadsheet app. Excel and libreoffice as far as I know have the capability to select the delimiter i.e as a space, tab or comma etc or fixed width so conversion is probably not necessary.
 
1 members found this post helpful.
Old 08-16-2019, 07:14 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
So if the OP had made some effort .... :shrug:
 
Old 08-16-2019, 08:01 AM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by michaelk View Post
Depends on spreadsheet app. Excel and libreoffice as far as I know have the capability to select the delimiter i.e as a space, tab or comma etc or fixed width so conversion is probably not necessary.
Quote:
Originally Posted by syg00 View Post
So if the OP had made some effort .... :shrug:
Agree and concur.

Not so proficient with the Linux varieties of spreadsheets, but I know that one can import data and many times there's a preview of that data which shows, and allows you to change you delimiter so that you can get it right, while viewing the previews.

So just try this, and I would prefer to stay away from a bunch of text processing tools. I do not feel they are necessary.

Or, to be kinder about it. Have you already tried this, and found it to be flawed in some manner?
 
Old 08-16-2019, 09:12 AM   #8
mjolnir
Member
 
Registered: Apr 2003
Posts: 815

Rep: Reputation: 99
Calc will import the file fine checking 'space' as a delimiter.
Off Topic: I understand the rationale for asking someone who just joined what they have tried but IMO grilling a Contributing Member who has 3500+ posts is unnecessary. Just my 2 cents.
 
1 members found this post helpful.
Old 08-16-2019, 09:45 AM   #9
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,720

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Smile

Quote:
Originally Posted by EmaRsk View Post
Code:
cat original_file | tr " " "\t" >converted_file
or
Code:
sed "s/ /\t/" original_file >converted_file
Hi EmaRsk. Thank you very much. Those are perfect!
 
Old 08-16-2019, 09:46 AM   #10
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,720

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Quote:
Originally Posted by pan64 View Post
The answer is: yes. You can also implement it easily in bash.
But from your side: Which language/tool do you prefer? What did you try so far? Where did you stuck?
Hi pan64. I'm not too fussed on the language. It's solved now anyway. Thanks.
 
Old 08-16-2019, 09:48 AM   #11
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,720

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Smile

Quote:
Originally Posted by mjolnir View Post
Calc will import the file fine checking 'space' as a delimiter.
Off Topic: I understand the rationale for asking someone who just joined what they have tried but IMO grilling a Contributing Member who has 3500+ posts is unnecessary. Just my 2 cents.
Hi mjolnir. Yes, that's ideal. Thank you.
Attached Thumbnails
Click image for larger version

Name:	calc.png
Views:	18
Size:	28.8 KB
ID:	31130  

Last edited by linustalman; 08-17-2019 at 09:26 AM. Reason: added 'Thank you.'
 
Old 08-16-2019, 03:19 PM   #12
jmccue
Member
 
Registered: Nov 2008
Location: US
Distribution: slackware
Posts: 691
Blog Entries: 1

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
I would use unexpand(1). It should already be on your distro
 
2 members found this post helpful.
Old 08-17-2019, 01:29 AM   #13
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,864

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
hm. I have never heard about expand/unexpand, both can be implemented easily in awk/perl/python/whatever, still interesting that we have a ready-made tool for this.
something to learn again.
 
Old 08-17-2019, 11:18 AM   #14
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,720

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Thumbs down

Quote:
Originally Posted by syg00 View Post
tr, sed, awk, perl, python, ...

Start with the manpage for tr.
So basically a slightly helpful rtfm then, right?

Last edited by linustalman; 08-17-2019 at 11:29 AM.
 
Old 08-17-2019, 11:18 AM   #15
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,720

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Thumbs down

Quote:
Originally Posted by syg00 View Post
So if the OP had made some effort .... :shrug:
Not very helpful at all.
 
  


Reply

Tags
spaces, spreadsheet, tabs



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Tabs or spaces? Spaces, obviously, but how many? LXer Syndicated Linux News 0 09-13-2018 09:50 AM
system froze when I clicked Save for Calc spreadsheet, now the spreadsheet is gone Stringdude Linux - Newbie 2 11-24-2010 01:05 AM
I got switched from a word process doc. into spreadsheet form. now ALL is spreadsheet 293 manzanita Linux - Newbie 1 08-04-2010 01:14 PM
Geany - How do you convert tabs to spaces? golmschenk Linux - Software 6 02-27-2010 04:06 PM
emacs - convert auto indent tabs to spaces? BrianK Linux - General 1 04-15-2004 10:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration