The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need to read data from a file (cut/awk) rejirajraghav Shell Programming and Scripting 1 04-29-2008 03:13 PM
read input file for batch job kinmak Shell Programming and Scripting 14 07-11-2007 07:22 AM
Read from data file fongthai Shell Programming and Scripting 12 02-27-2007 09:22 PM
Reading in data sets into arrays from an input file. sidamin810 Shell Programming and Scripting 5 07-06-2005 07:54 AM
read a file as input and pass each line to another script sajjad02 Shell Programming and Scripting 0 09-24-2004 11:13 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-22-2006
dorek dorek is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 2
scripts that allow searches, edits, and deletes of your file

Hi,

how can i do to show when i do with scrip list entris, or list specific entry, it show 2 lines when i specify the entry to search...¿?
i paste the script:

Code:
# Global variables
film=/opt/etc/film/film.txt
export film

confirm()
{
  echo -en "$@"
  read ans
  ans=`echo $ans | tr '[a-z]' '[A-Z]'`
  if [ "$ans" == "Y" ]; then
    return 0
  else
    return 1
  fi
}

num_lines()
{
  grep -i "$@" $film|wc -l| awk '{ print $1 }'
}

find_lines()
{
  # Busca lineas de entrada $1
  res=-1
  if [ ! -z "$1" ]; then
    grep -i "$@" $film
    res=$?
  fi
  return $res
}

list_items()
{
  # Lista los resultados encontrados
  if [ "$#" -eq "0" ]; then
    echo -en "Buscar usuario: (en blanco muesta toda la lista): "
    read search
    if [ -z "$search" ]; then
      search="."
    fi
    echo
  else
    search="$@"
  fi
  find_lines "${search}" | while read i
  do
    echo "$i" | tr ':' '\t'
  done
  echo -en "Encontrados: "
  num_lines "$search"
}

add_item()
{
  echo
  echo
  echo
  echo "          NUEVA PELI"
  echo " COMPLETA TODOS LOS DATOS"
  echo "  - AÑO MES DIA DIRECTOR TIPO - "
  echo
  echo -en "Nombre: "
  read name
  find_lines "^${name}:"
  if [ `num_lines "^${name}:"` -ne "0" ]; then
    echo "El usuario, $name ya existe en el fichero."
    return
  fi
  echo -en "Año: "
  read "ano"
  echo -en "Director: "
  read filmaker
  echo -en "Genero:"
  read genre
  echo -en "Calificacion:"
  read calification

  # Confirmacion
  echo "${name} Password=${ano}
        ${calification}, ${filmaker}, ${genre}" >> $film
  echo
  echo
  echo -en "--> ALTA FILM"
  echo
  echo
}

locate_single_item()
{
  echo -en "Peli a buscar: "
  read search
  n=`num_lines "$search"`
  if [ -z "$n" ]; then
    n=0
  fi
  while [ "${n}" -ne "1" ]; do
    #list_items "$search"
    echo -en "${n} peli encontrada. Selecciona una "
    case "$n" in
      "0") echo "menos" ;;
      "*") echo "mas" ;;
    esac
    echo "especifica un patron de busqueda (q para volver al menu anterior): "
    read search
    if [ "$search" == "q" ]; then
      return 0
    fi
    n=`num_lines "$search"`
  done
  return `grep -in $search $film |cut -d":" -f1`
}

#remove_item()
#{
#  locate_single_item
#  search=`head -2 $film`
#  if [ -z "${search}" ]; then
#       return
#  fi
#  list_items "$search"
#  confirm "Borrar?"
#  if [ "$?" -eq "0" ]; then
#    grep -v "$search" $film > ${film}.tmp ; mv ${film}.tmp ${film}
#  else
#    echo "NO BORRADO"
#  fi
#}

edit_item()
{
  locate_single_item
  search=`head -$? $film | tail -1|tr ' ' '.'`
  if [ -z "${search}" ]; then
        return
  fi
  list_items "$search"
  thisline=`grep -i "$search" $film`
  oldname=`echo $thisline|cut -d"" -f1`
  oldano=`echo $thisline|cut -d"," -f2`
  oldfilmaker=`echo $thisline|cut -d"," -f3`
  oldcalification=`echo $thisline|cut -d"," -f4`
  oldgenre=`echo $thisline|cut -d"," -f5`

  echo "BUSCAR : $search"
  grep -v "$search" $film > ${film}.tmp ; mv ${film}.tmp ${film}
  echo -en "Pelicula [ $oldname ] "
  read name
  if [ -z "$name" ]; then
    name=$oldname
  fi
  find_lines "^${name}:"
  if [ `num_lines "^${name}:"` -ne "0" ]; then
    echo "La pelicula, $name esta en el fichero."
    return
  fi
  echo -en "ano [ $oldano ] "
  read ano
  if [ -z "$ano" ]; then
    ano=$oldano
  fi
  echo -en "Pelicula [ $oldfilmaker ] "
  read filmaker
  if [ -z "$filmaker" ]; then
    filmaker=$oldfilmaker
  fi
  echo "${name}:${ano}:${filmaker}" >> $film
}



Scripts I need that allow search, edit, and delete data from you file.


how can i do..??


thank your for your help.
please i need your help..!
cheers.

dorek

Last edited by dorek; 06-22-2006 at 11:57 AM..
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0