The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script for text extraction from a file vignesh53 Shell Programming and Scripting 3 02-05-2008 05:16 AM
AWK extraction harris2107 Shell Programming and Scripting 2 01-15-2008 08:44 AM
AWK extraction harris2107 Shell Programming and Scripting 3 08-17-2007 02:02 AM
Data Extraction issue. irehman Shell Programming and Scripting 5 04-06-2006 05:28 AM
Help with tar extraction! manthasirisha Shell Programming and Scripting 4 03-17-2006 04:17 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-09-2008
mam mam is offline
Registered User
 

Join Date: Jan 2008
Posts: 6
help with data extraction script

Hello all,
Iam newbie here and to unix programming. I have the following text file.
Code:
A:Woshington,B:London,C:Paris,D:Manchester,C:Lisbon,E:Cape town.
Now I would like extract this and store in database. here is the script I have tried but it did work.
Code:
CITY1:`echo "$text" | grep "A:" |awk '{print $0 }'`
CITY2 :`echo "$text" | grep "B:" |awk '{print $0 }'`
CITY3:`echo "$text" | grep "C:" |awk '{print $0 }'`
CITY4:`echo "$text" | grep "D:" |awk '{print $0 }'`
CITY5:`echo "$text" | grep "E:" |awk '{print $0 }'`
CITY6:`echo "$text" | grep "F:" |awk '{print $0 }'`
Thanks in advance for your help.
mam
Reply With Quote
Forum Sponsor
  #2  
Old 01-09-2008
Registered User
 

Join Date: Dec 2006
Posts: 131
How you need the output?Are you looking for the entire block seperated with colon or just the City name ?
Reply With Quote
  #3  
Old 01-09-2008
mam mam is offline
Registered User
 

Join Date: Jan 2008
Posts: 6
DILEEP410,
Thanks for your reply,
For the output, I need only city names and then I will use them to store in database.
like CITY1=Washington,CITY2= ...,

Thank you again for your help
mam
Reply With Quote
  #4  
Old 01-09-2008
mam mam is offline
Registered User
 

Join Date: Jan 2008
Posts: 6
Sorry I think the code should read like this
Code:
CITY1=`echo "$text" | grep "A:" |awk '{print $0 }'`
CITY2 =`echo "$text" | grep "B:" |awk '{print $0 }'`
CITY3=`echo "$text" | grep "C:" |awk '{print $0 }'`
CITY4=`echo "$text" | grep "D:" |awk '{print $0 }'`
CITY5=`echo "$text" | grep "E:" |awk '{print $0 }'`
CITY6=`echo "$text" | grep "F:" |awk '{print $0 }'`
Reply With Quote
  #5  
Old 01-09-2008
mam mam is offline
Registered User
 

Join Date: Jan 2008
Posts: 6
Please, anyone with idea?.
I really need your support expert!
Thank you again
Reply With Quote
  #6  
Old 01-09-2008
Registered User
 

Join Date: Jan 2008
Posts: 2
passing paramaters to a shell variable

could some one tell me, how could i pass the wilcard notation given as input to variable $1 which acts as variable that matches files in the directory and the delete them.
Reply With Quote
  #7  
Old 01-09-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
GNU awk
Code:
awk 'BEGIN{FS=",*[a-zA-Z]:"}
{
  for ( i=2 ; i<=NF ; i++ ) {
    print "insert table values (\047" $i "\047)"
  }
}
' "file"
output:
Code:
# ./testnew.sh
insert table values ('Woshington')
insert table values ('London')
insert table values ('Paris')
insert table values ('Manchester')
insert table values ('Lisbon')
insert table values ('Cape town.')
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0