Help on editing inventory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on editing inventory
# 1  
Old 07-16-2010
Help on editing inventory

Hi guys, im currently doing a library database program, and i need help for the following commands

my library.txt is
Code:
Google:Harry:45.00:50:100

This is my code
Code:
echo "Please enter Title"
    read BookTitle
    echo "Please enter Author"
    read Author
    echo "Price"
    read Price
    echo "Quantity"
    read Quantity
    echo "Sold"
    read Sold
    echo "$BookTitle:$Author:$Price:$Quantity:$Sold" >> library.txt
    echo " Book Added Successfully!"

My question is, what commands can i put in in order to commit the following output so that when there is an existing book of the SAME title AND author, the following output will be shown
Output 1
Code:
Book already exists

and if Book Title and/or Author contains invalid chars like (0-9, !@#$%), and then reprompting them to input the book title again.
Code:
Please enter valid Title/Author

Many thanks.
# 2  
Old 07-16-2010
add a test

You need to add a test to check if the sequence $BookTitle:$Author is present in the file library.txt :

Code:
#!/bin/bash
echo "Please enter Title"
read BookTitle
echo "Please enter Author"
read Author
if [[ $(grep "^$BookTitle:$Author" library.txt | wc -l) -gt 0 ]]
then echo "Book already exists"
else 
    echo "Price"
    read Price
    echo "Quantity"
    read Quantity
    echo "Sold"
    read Sold
    echo "$BookTitle:$Author:$Price:$Quantity:$Sold" >> library.txt
    echo " Book Added Successfully!"
fi

I have a small bash tuto online : Unix reminder

Fabrice.
# 3  
Old 07-16-2010
Quote:
Originally Posted by ichar
... and if Book Title and/or Author contains invalid chars like (0-9, !@#$%), and then reprompting them to input the book title again.
Code:
Please enter valid Title/Author

Code:
case "$Author$BookTitle" in
    *[0-9,\!@#$%\(\)]*)  echo "Please enter a valid Title/Author" ;;
esac

However, if this were for something real, you would soon encounter a valid book title with funny characters in it.
For example, the number one book on the NYTimes hardcover nonfiction best seller list right now with an * in the title.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Server inventory software

Hi, do you know any good server inventory open source products? I want information like, server hostnames, ram, cpu, os, filesystems, volume groups, disks, adapters, installed software versions, firmware levels and so on os: aix, solaris, linux, hpux data should be kept in a database, web... (7 Replies)
Discussion started by: funksen
7 Replies

2. Shell Programming and Scripting

Convert vi editing to text editing

Dear Guru's I'm using Putty and want to edit a file. I know we generally use vi editor to do it. As I'm not good in using vi editor, I want to convert the vi into something like text pad. Is there any option in Putty to do the same ? Thanks for your response. Srini (6 Replies)
Discussion started by: thummi9090
6 Replies

3. Solaris

Inventory details - Solaris

i need to extract following information through command line on solaris machine : 1.manufacturer name (hardware as well as OS) 2.Model number 3.Serial number - Serial Number of the device or the Physical device serial number for Virtual Servers 4.whether the server is physical or virtual -... (3 Replies)
Discussion started by: omkar.jadhav
3 Replies

4. UNIX for Dummies Questions & Answers

Folders and Files Inventory

Hi , We are migrating our scripts from one unix server to another unix server in aix. Is there any way we can export the permissions, owner, group of the folders and files inside the folders. If I am copying xyz folder from old server, I need to generate a report with permissions ,owner and... (5 Replies)
Discussion started by: shruthidwh
5 Replies

5. Shell Programming and Scripting

Scripting for Inventory

Hi, I am getting all the scripts in my unix box through ls and pasting them in a xls for the Inventory Purpose. Right now I am doing it manually I am going manually in each directory and doing a ls > temp.txt and pasting this out put in xls manually. Is there any way to automate this ..if... (1 Reply)
Discussion started by: gaur.deepti
1 Replies

6. Shell Programming and Scripting

File Inventory Scan

Is there such a script out there that will Analyze a folder and subfolders, getting file type utilization and file aging. A CSV file will be created with file information File,Size,Date Created,Last Modified,Last Accessed,Extension,File Type,Owner A Summary report text file will also be created... (4 Replies)
Discussion started by: seacros
4 Replies

7. UNIX for Advanced & Expert Users

Collecting software inventory

how to obtain/ collect a list of all the applications installed in the system.. is there a configuration file(like the one which exists for hardware ) which holds all this information?? if no is there any command/shell script or utility that we can use for the same ?? I am using Red hat linux... (2 Replies)
Discussion started by: superghost
2 Replies

8. UNIX for Dummies Questions & Answers

Software Inventory

How can I find out what software is installed on the machine, other than ls? Is there a registry program like in Windows? The os is Sun 2.5. Thanks (1 Reply)
Discussion started by: ViperD
1 Replies
Login or Register to Ask a Question