Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to get data from a file

Posted on 1999-07-08
8
Medium Priority
?
255 Views
Last Modified: 2010-04-21
helloo..., I've been wondering... how do i write a shell script to write a data structure (name, age, phone number) into a file and recalls that data again from that file???
0
Comment
Question by:techpage
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Expert Comment

by:bedot
ID: 2011396
1° to create (extract from an exercice of a student)
...
      echo "Nom : \c"
      read nom
do
  if [ -z "$nom" ] 2>/dev/null
  then
    clear
    break
  else
    echo "Prenom : \c                                       "
    read prenom
    echo "Ville : \c                                        "
    read ville
    echo "Telephone : \c"
    read tel
    nom=`echo $nom | tr ' ' '_'`
    prenom=`echo $prenom | tr ' ' '_'`
    ville=`echo $ville | tr ' ' '_'`
    nom=`echo $nom | tr ' ' '_'`
   # ajout dans fichier par printf pour unix 4.0
    printf '%-13.13s %-13.13s %-20.20s %-8.8s \n' $nom $prenom $ville $tel >> fi
chagent
   # ajout dans fichier par echo pour unix  3.2
   # echo $nom $prenom $ville $tel >> fichagent
   # echo " " >> fichagent
....

2° to print the content formatted

...

  cat ficagent | (while read nom prenom ville tel
    do
      printf '%1s %-13.13s %1s %-13.13s %1s %-20.20s %1s %-14.14s %1s \n' $b $nom $b $prenom $b $ville $b $tel $b
    done)

...

to search a line containin a criteria, use grep
0
 
LVL 3

Author Comment

by:techpage
ID: 2011397
Thanks.. but i've tried the source, it can't run... and I don't understand the language !! please make sure you give me the complete source.... *sob*...
0
 
LVL 84

Expert Comment

by:ozo
ID: 2011398
What shell languages do understand?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:bedot
ID: 2011399
Sorry i can no more for you
0
 
LVL 2

Expert Comment

by:khaled022498
ID: 2011400
ozo wanted to say what is the shell you are using ??, is it ksh ,csh ,sh ,... becuase each shell has it's own charactaristics.

0
 
LVL 3

Author Comment

by:techpage
ID: 2011401
ummm... i'm using sh... bourne shell !!!
0
 

Accepted Solution

by:
emmle earned 200 total points
ID: 2011402
Hi TechPage,

How about using a combination of echo "Name: \c", read name, echo "Age: \c", read age etc.. as Bedot suggested (in order to grab the data that you want), followed by echo $name,$age,$phonenumber>>TechPage where TechPage would be a comma delimited file containing all the relevant details you are interested in.
Then all you need to do is to use a combination of "grep" in order to only retrieve the desired records and "cut" in order to retrieve the desired field (do "man cut" to see what options you need to use. The one you want is the delimiter option (possibly -d but I am not 100% sure, you need to check). Use "," to tell the command that it is the delimiter you have been using. The position of the column will give you the field you are after.
For instance, if your record looks like this:
Name,Age,Telephone Number. Name will be column 1, Age column 2 etc...
Once again, if you do a "man cut", it will make more sense.

I hope this helps.

0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6821542
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects that and the expert will now receive these points, all verified.

Please click on your Member Profile, select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.
 
Thanks,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question