Wednesday, June 25, 2008

Opening CSV or Text Files as Calc Spreadsheets--and Vice Versa

(link to original post)
When I worked at Sun, there were a few things people always asked, that were hard to figure out.

- How do you print the same rows or columns on every page of a spreadsheet? (See this post. )

- How do you print handouts for a presentation? (See this post.)

- How do you get a blank paragraph line above a table that's at the top of a document? (You now simply have to press Return in the upper left cell of the table.)

Another very common question was:

How in the world do you open a perfectly good .txt or .csv file (comma-separated values) in a spreadsheet? Basically, you've got data in rows and columns, but separated by tabs or commas rather than columns in a spreadsheet, and you want it in a spreadsheet. Comma-delimted files are a common way to get data out of a spreadsheet or database and into another.

The trouble is, in OpenOffice.org, if you just choose File > Open, the .txt or .csv file opens in Writer. Not what you want.

Csv1_1

Here's how to open it in a Calc spreadsheet.

Opening a .txt or .csv File in a Calc Spreadsheet

1. Start OpenOffice.org. You can be in Writer, Draw, Calc—it doesn't matter.

2. Choose File > Open. (Click the picture to see a larger version of it, if you want.)

Csv0_1

3. In the File Type list, select Text CSV. It's about a third of the way down the list of types, or you can click in the file type list and press T four times.

List_2

4. The window should now look like this, so just click Open.

Csv2

5. You'll get a window where you specify how the file was created: what separates the data into columns, etc. (Click the picture to see a larger version, if you want.)

Csv3

6. Also in the same window, if you have date-format data or other formats you want to specify, you can do that column by column.

Csv4

7. When you're done, just click OK. You'll see the data in a spreadsheet.

Csv5

8. You'll want to save it as a spreadsheet at some point. Choose File > Save As and select the standard OpenSpreadsheet .ods format.

Csv6

9. Click Save.

Saving a Calc Spreadsheets as a .txt or .csv File

1. Let's say it's the other way around—you've got a spreadsheet and you want it to be in a nice neutral .txt or .csv file. Be sure the file is open.

2. Choose File > Save As and select the same Text CSV format in the file format list. This time you can click T just once.
Csvsaveas

3. Click Save.

4. You'll probably see this message. Click Yes.

Saveas1

5. In the next window, specify the type of character you want to separate columns, commas or tabs or another character.
Saveas2_1

6. Click OK; you're done.

HowTo: Copy and Paste A Text File into Another Text File via Terminal

(link)
Yes, you read correct. This time around, we are going to paste data content of one text file into another text file and we are going to approach this issue using linux command via terminal. This one could be easily done inside X or GNOME, but let us assume we are going to do it from a linux system without X, say server or remote non-X linux box, something like that.

Let's start.

Let us view two example of text files namelyh textfile1.txt and textfile2.txt

# cat textfile1.txt
RedHat
Fedora
CentOS

# cat textfile2.txt
Enterprise Version
Core Version 9
Linux Distro


Now, let us merge or combine two text files using the linux paste command

# paste textfile1.txt textfile2.txt
result:
RedHat Enterprise Version
Fedora Core Version 9
CentOS Linux Distro


Making it permanent as file would be as easy as

# paste textfile1.txt textfile2.txt > output.txt

Did you noticed that the contents of textfile2.txt was merged with the data contents of textfile1.txt? Noticed also the fixed columnar width making the 2nd column word vertically aligned.

Merging two text file using paste could be very useful on specific scenarios of merging related data contents.

Here's another scenario.

# cat test1.txt
Citybank
Citybank
BPI Bank
Citybank

# cat test2.txt
New York, USA
San Francisco, USA
Manila, Philippines
London, UK

Again, using paste to merge contents of first file and second text file

# paste test1.txt test2.txt
result:
Citybank New York, USA
Citybank San Francisco, USA
BPI Bank Manila, Philippines
Citybank London, UK

If you want to insert a delimeter character between two columnar data or data field, that could be done using the same linux paste command like so

# paste -d", " test1.txt test2.txt
result:
Citybank,New York, USA
Citybank,San Francisco, USA
BPI Bank,Manila, Philippines
Citybank,London, UK


Neat and nice, isn't it? Hope you enjoy it, and oh, it was an old idea reminded to me by pinoyskull.

Merging two text files with a common field or column marker would be my next post, so watch out for it. And sorry for late updates, been very busy these past few weeks.

Related Posts:
Merging Linux Non-Text and Binary Files
Concatenating Multiple Linux Files
Simple Linux Text Line Formatter
Math the Beauty and Linux the Beast
Retrieve MySQL data via Bash Shell

===============================

To add text to the end of a file:
$ cat footnotes.txt >> file

If you're appending only a single line instead of multiple lines or an entire file, you can use echo instead of cat:

$ echo "192.255.255.255 bigblue" >> /etc/hosts

To append lines of text that are itemized beginning with 1, use cat's -n option; lines are preceded with the line number (offset with up to five space characters) and a tab character. Add the -b option to suppress the numbering of blank lines:

$ cat -nb > file
This line is numbered

And so is this


Another numbered line Ctrl-D

$ cat file
1 This line is numbered
2 And so is this

3 Another numbered line
$

Wednesday, June 18, 2008

SUDO PASWORD IN UBUNTU

One way to gain root prompt is to launch a shell as root. Therefore, using sudo you can type:

:~$ sudo sh
Password:
sh-3.1#

And there you are, you have a root shell.

If you want to be able to login as root, you need to define a password for root:

:~$ sudo passwd
Password:
Enter new UNIX password:
Retype new UNIX password:

Now you can login as root with su.

Re-disabling your root account

If for some reason you have enabled your root account and wish to disable it again, open a terminal and issue the following command:

sudo passwd -l root

Monday, June 02, 2008

inadyn

https://help.ubuntu.com/community/DynamicDNS
Install the inadyn package using Synaptic Package manager, then:

The following will allow your Ubuntu Linux machine to be accessible anywhere that you are given an externally-accessible IP address. This includes most ISPs but excludes many office LANs.

First edit the file /etc/inadyn.conf:

gksudo gedit /etc/inadyn.conf

It should contain something like to the following:

--username myusername
--password mypassword
--update_period 60000
--alias myhost.dyndns.org
--background

Now test that it works by typing

sudo /usr/sbin/inadyn

Next, add inadyn to your 'crontab':

export EDITOR=gedit
sudo crontab -e

Edit the file to add the following additional line:

@reboot /usr/sbin/inadyn

Then save and exit the editor. Verify using

sudo crontab -l

When you reboot, you should see indyn listed when you type

ps -A | grep inadyn

You should be able to log in to your Dynamic DNS provider's website and verify that the DNS entry is being updated. Certainly this is possible with www.dyndns.org, in any case. Alternatively you can type your hostname into a service like [WWW] http://www.dnsstuff.com/.
===========//////

Through DynDns website can be generated the inadyn.conf file which is something like this:

# Basic configuration file for inadyn
#
# /etc/inadyn.conf

update_period_sec 600 # Check for a new IP every 600 seconds

username "mylogin"
password "mypassword"

dyndns_system dyndns@dyndns.org
alias test.homeip.net