Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2007
    Posts
    25

    Unanswered: Extracting a string from a line

    Hi Experts,

    I want to extract the table name and the database names using shell scripts from a file which contains the following

    select D.dept_id,E.emp_name, E.emp_addr from department:t_dept D,employee:t_emp E where D.emp_id = E.dept_id

    here department and employee are the database names
    and t_dept and t_emp are the tablenames

    Thanks in advance.

    Regards,
    Poornima.

  2. #2
    Join Date
    May 2007
    Location
    Milano, Italy
    Posts
    22
    With GNU grep:

    Code:
    grep -o '[[:alnum:]]*:[[:alnum:]_]*' data
    Or use Awk for more flexible manipulation:

    Code:
    awk 'NF>1{sub(/.*,/,"");printf "database: %s, table_name: %s\n",$1,$2}' FS=":" RS=" " data

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •