Script problem with deleting data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script problem with deleting data
# 1  
Old 05-27-2012
The code doesnt delete records on the file.

The 10.Delete data doesnt work at all, plesase anyone could help on that. When I choose options 10 to delete a record it only copy the selected data on the other file dbs1 but doesnt delete it from the database where other records are.
Code:
#! /bin/bash
i="y"
echo "Enter name of database "
read db
while [ $i = "y" ]
do
clear
echo "1.Enter id "
echo "2.Display current dir"
echo "3.Listing the dir"
echo "4.Make a dir"
echo "5.Copy a file"
echo "6.Rename file"
echo "7.Delete file"
echo "8.Edit file"
echo "9.Add e record"
echo "10.Delete data"
echo "11.Exit"
echo "Enter your choice"
read ch
case $ch in
1)echo "Enter id "
read id
grep -i "$id" $db ;;
2)echo "Current Dir is : "
  pwd;;
  3)echo "Directories are"

    ls;;
    4)echo "Enter dir name to create"
     read d
             mkdir $d
                 echo $d" Dir is created";;
             5)echo "Enter filename from copy"
              read f1
               echo "Enter filenm2 to be copied"
                read f2
                    #cat $f1 > $f2
                        cp $f1 $f2
                            echo $f2" is copied from "$f1;;
                        6)echo "Enter file name to rename"
                         read f1
                          echo "Enter new name of file"
                           read f2
                                   mv $f1 $f2
                                       echo $f1" is renamed as "$f2;;
                                   7)echo "Enter any filenm to be delete"
                                    read f1
                                            rm $f1
                                                echo $f1" is deleted";;
                                            8)echo "Enter any file to be editing "
                                             read f1
                                                     vi $f1;;
9)echo "Enter the name"
read kdi
echo “$kdi” > dbkodi
cat dbkodi
echo "Enter the profesion:"
read tpi
echo ”$tpi” > dbtitulli
cat dbtitulli
echo "Enter the school "
read ept
echo “$ept” > dbemri_piktorit
cat dbemri_piktorit
echo "Enter the class"
read cmm
echo ”$cmm” >dbcmimi
cat dbcmimi
echo "$kdi $tpi $ept $cmm">>$db;;
10)echo "Enter Id"
read id
# set -a
sed '/$id/d' $db > dbs1
grep -v "$id" $db > dbs1
echo "Record is deleted"
cat dbs1;; 

                                                 11)echo "Have a nice time"
                                                 exit;;
                                                 *)echo "Invalid choice entered";;
                                                 esac
                                                 echo "Do u want to continue ? "
                                                 read i
                                                 if [ $i != "y" ]
                                                 then
                                                 exit
                                                 fi
                                                 done


Last edited by Lina_14; 05-27-2012 at 11:13 AM.. Reason: Please wrap code and data with CodeTags; please use descriptive titles
# 2  
Old 05-27-2012
What doesn't work?

Please show an example of how it is not working.
Not working at all, only partially, etc...
This User Gave Thanks to joeyg For This Post:
# 3  
Old 05-27-2012
When I put the ID of the data I want to remove it only copy the data to dbs1 and doesnt delete it from the database in which are the other datas.
# 4  
Old 05-27-2012
Why both commands?

Code:
sed '/$id/d' $db > dbs1
grep -v "$id" $db > dbs1

In theory, the 2nd command is how you could remove data from a file.
# 5  
Old 05-27-2012
it just doesnt work even if the mesagge printed is "Data deleted", anyway thanx for the replay Smilie
# 6  
Old 05-27-2012
What happens if you manually execute that command?
Or, execute the command without the -v option? Without the -v option, the result would demonstrate what meets the criteria.
Code:
grep -v "stuff" <myfile

should copy all except for lines with "stuff"
while,
Code:
grep "stuff" <myfile

would show you what contains "stuff"

As I read your code, I do not think the grep is analyzing the input file. It is early on a Sunday morning for me, but I think you would want something like:

Code:
grep -v "stuff" <myfile >mynewfile

This User Gave Thanks to joeyg For This Post:
# 7  
Old 05-27-2012
Still the same :(

its pretty the same when I exeute the comand without -v, I mean its a way better in terminal but still doesnt delete the data from database, maybe its something wrong with the whole code, idk...Thank you for your kind replay, apreciate it Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting data

Need Assistance in a script to delete date for Below example There are four period(.) line . I wanted to delete 2 period(.) from below . 5 .TODAY...MOSTLY SUNNY. HIGHS 58 TO 63. LIGHT WINDS IN THE MORNING 6 BECOMING NORTH 10 TO 15 MPH IN THE AFTERNOON. 7 .TONIGHT...MOSTLY CLEAR.... (5 Replies)
Discussion started by: ajayram_arya
5 Replies

2. UNIX for Dummies Questions & Answers

Deleting the unwanted data based on condition

hi i have my input data like this aaa bbb ccc asa dff nmj mnj saa dff oik aax cdx saa oik asq sdf dssi want my output file to be like this mnj saa dff oik aax cdx saa oiki want to retain only those lines which will have oik just below them and i want oik to be as next column to those... (1 Reply)
Discussion started by: anurupa777
1 Replies

3. Shell Programming and Scripting

Help with database deleting data!!!

Hi, I'm new to programming in shell and I wanted to make a simple database on shell script but I'm having trouble in deleting data. I would apreciate any kind of help. Thank you in adavanced. (7 Replies)
Discussion started by: Lina_14
7 Replies

4. Shell Programming and Scripting

some strange problem with return data in script

Hi, I have come across a little strange problem in my script. i tried the same logic in some other script where its working fine. but in other script its not behaving as expected. Here is the code: #!/bin/bash run_count="2" catalog_name="demo" cd... (3 Replies)
Discussion started by: sukhdip
3 Replies

5. Shell Programming and Scripting

Insert row without deleting previous data using sed

Hello, I want to add a new row to a file to insert data without deleting the previous data there. Example: file a b c d Output a b newtext c (6 Replies)
Discussion started by: joseamck
6 Replies

6. Shell Programming and Scripting

Deleting shorter lines from data file

Hello, I have the following data file structure: 1234 text 2345 text 3456 text text text 4567 text text text 5678 text text text 6789 text text text I simply want to delete all of the lines that only have one text column (i.e. the first two lines in this case). The output would be:... (1 Reply)
Discussion started by: palex
1 Replies

7. Shell Programming and Scripting

Problem running Perl Script with huge data files

Hello Everyone, I have a perl script that reads two types of data files (txt and XML). These data files are huge and large in number. I am using something like this : foreach my $t (@text) { open TEXT, $t or die "Cannot open $t for reading: $!\n"; while(my $line=<TEXT>){ ... (4 Replies)
Discussion started by: ad23
4 Replies

8. Shell Programming and Scripting

Problem - script that parses $date data...

This is probably archaic, but I'm new to unix and this is my first shell script. I'm writing this script to use in another script. All I am trying to do is make the parts of the output from date usable in my other script. I was wondering if you could stand looking at this and see if you notice... (8 Replies)
Discussion started by: Dalcron
8 Replies

9. AIX

Permanentky deleting data from disk drives for a decommissioned server.

I am about to retire several servers and need to delete the company confidential data from the internal disks under LVM control. Is there a proven and easy way to accomplish this ? Thanks for all the help in advance. (4 Replies)
Discussion started by: thenomad
4 Replies
Login or Register to Ask a Question