Creating a simple ID Script

Hello everybody,

:wall:I am new to Linux and I want to create a simple script on Ubuntu that will allow to make database with a few perimeters.

create file and name it Database and complete it with any information

id     firstname     lastname     phone
 0
 1
 2
 3
 4

:wall:command to extract Id and insert it in new file "file1"
:wall:command to extract lastname and insert it in new file "file2"
:wall:command to extract phone and insert it in new file "file3"

:wall:command to combine "file1", "file2" and "file3" in a new file and name it "file4"

Any suggestions will be kindly helpful.:slight_smile:

And what are your attempts at solving this? :slight_smile:

To start with, you'll need to learn the following:

  1. How to read lines from a file. Read about file handling using while loop. There are crude versions using for loop. While "for" is efficient for file reading in python, it's bad in shell scripts. Learn why it is so.
  2. In while loop, learn how to read lines as fields. What does IFS mean? What's the default value in IFS? What do you need to set it as?
  3. How to write contents to a file. Hint: echo

Let us know what you could come up with.

Is this a homework assignment? Homework and coursework questions can only be posted in the Homework & Coursework Forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

If you did post homework in the main forums, please review the guidelines for posting homework and repost. Otherwise, please explain how this database will be used.

Its not an hw assignment, more of just preparing for a class next quarter. I been trying to get a head start on some the things that might be required.

I will post in the HW section next time. Sorry about that. :slight_smile:

---------- Post updated at 11:59 AM ---------- Previous update was at 11:56 AM ----------

I have been looking at examples and researching online. I have some experience in Python.

Would I use the same functions in Linux/Ubuntu as I would in Python?

"Linux" (or "Unix", for that matter) is not a programming environment. Unixes (this includes Linux) use certain "shells" (commando processors, if you are proficient with Windoze: think of something similar in function to CMD.EXE, but with the capabilities of PowerShell included from the start).

Most of the shells (and all of the common ones) are not only built for interactive use but also have built-in languages which you can use to write programs ("scripts"). The syntax of these languages are quite similar, but not the same.

Today the overwhelming majority of scripting is done in one of two shells: bash (Bourne Again SHell) and ksh (Korn Shell). Both these languages are based on an older shell (the Bourne shell) and downwards compatible to it, so scripts written in strict Bourne shell code will run in both these shells and produce the same results. There is a newer standard to scripting, POSIX shell, which is based mostly on the Korn shell and both, bash and ksh are able to understand that standard. Both offer (different) features though, which are not part of this standard.

Linux distributions (not Ubuntu) usually come equipped with bash as the default shell, but can easily be changed to use the Korn shell, which is freely available today. Of the commercial Unixes some come with ksh (Solaris, AIX, if i remember correctly HP-Ux), some with Bourne shell (SCO, IRIX, and maybe - i can't remember - Tru64) but can utilize bash (which is also freely available) too.

Understand, that the shell language usually only covers the languages structure: you use system commands like you would use library functions in a high-level language. If you use everything your system offers it is likely that the next (different) system might not understand everything, like if you use the specialities of a certain compiler you may have to change your code if you switch to another compiler. This is why seasoned script programmers stay with the commands and options described in POSIX almost religiously, because this way they are guaranteed that their script runs on other platforms the same way it does so on theirs.

I hope this helps.

bakunin