help with data extraction script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with data extraction script
# 8  
Old 01-09-2008
Hope this will help u

text="A:Woshington,B:London,C:Paris,D:Manchester,C:Lisbon,E:Cape town"
CITY1=`echo "$text" |awk -F, '{ for(i=1;i<=NF;i++) if($i ~ "^A:") print substr($i,3);}' `
echo $CITY1
# 9  
Old 01-09-2008
MySQL

I think you shoud use arrays in this case
and I am also not sure if the file that contains the name of the cities contains only one line or more.

for example if it contains only onle line like


:~/st [164]> cat city_names
ASmilieelhi,B:Mumbai,C:Calcutta,D:Pune,E:Gurgaon


and you know the number of cities, you can do something like

let i=1
let flag=0

#while [ $flag -eq 0 ]
while [ $i -le 5 ]
do
let p=$i+1
CITY[$i]=`head -1 city_names | cut -d ':' -f$p | cut -d ',' -f1`
let i=$i+1
done>error 2>&1

let j=1
while [ $j -le 5 ]
do
echo ${CITY[$j]}
let j=$j+1
done



which will give you output like

:~/st [166]> ./scr
Delhi
Mumbai
Calcutta
Pune
Gurgaon




where
CITY[1] : Delhi
CITY[2] : Mumbai

etc
# 10  
Old 01-09-2008
Hello,
ranjithpr,snowline and ghostdog74,
Thank you for your reply.I will try to implement soon.
Also,it looks like I was not clear ,here is the really scenario:
Code:
text file
 A:Washington,B:Paris,D:London,C:Cape Town,E:Copenhagen,F:Mumbai
 The problem is on this part here:

 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 }'`
 
  if [ "$SQL_PASSWORD" != "" ]; then
     SQL_ARGS="-p$SQL_PASSWORD";
     else
     SQL_ARGS="";
     
   fi

  SQL_ARGS="-h $SQL_HOST -u $SQL_USER $SQL_ARGS -D $SQL_DATABASE -s -e"
  
  mysql $SQL_ARGS  " insert into $SQL_TABLE(city1,city2,city3,city4,city5,city6) values
(\"CITY1\",\"$CITY2\",\"$CITY3\",\"$CITY4\",\"$CITY5\",\"$CITY6");";

Thank you again.
# 11  
Old 01-11-2008
awk

Hi,

Try follow one.

Code:
cat file | tr -s "," "\n" | nawk 'BEGIN{OFS=FS=":"}
{
$1=sprintf("city%d",NR)
print
}'

# 12  
Old 01-16-2008
Data extraction software

I came across a data extraction software that works well on windows, i got it from mountonetech.com, see if they have similar data extraction software for unix environment.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Data extraction from .xml file

Hello, I'm attempting to extract 13 digit numbers beginning with 978 from a data file with the following command: awk '{ for(i=1;i<=NF;i++) if($i ~ /^978/) print $i; }' datafile > outfile This typically works. However, the new data file is an .xml file, and this command is no longer working... (6 Replies)
Discussion started by: palex
6 Replies

2. Shell Programming and Scripting

CSV file data extraction

Hi I am writing a shell script to parse a CSV file , in which i am facing a problem to separate the columns . Could some one help me with it. IN301330/00001 pvavan kumar limited xyz@ttccpp.com IN302148/00002 PRECIOUS SECURITIES (P) LTD viash@yahoo.co.in IN300239/00000 CENTRE india... (8 Replies)
Discussion started by: nanduri
8 Replies

3. UNIX for Dummies Questions & Answers

Need help for data extraction if files

Hello all, I want to extract some particular data from a files and than add all the values . but i m not able to cut the particular word(USU-INOCT and USU-OUTOCT) as it is coming not in column. and than able to add values coming in it . can anyone help me Please cat <file name> ... (7 Replies)
Discussion started by: anamdev
7 Replies

4. Shell Programming and Scripting

data extraction from a file

Hi Freinds, I have a file1.txt in the following format File1.txt I want to get 2 files from the above file filextra.txt should have the lines which are ending with "<" and remaining lines in the filecompare.txt file. Please help. (3 Replies)
Discussion started by: i150371485
3 Replies

5. Shell Programming and Scripting

Data Extraction problem in perl

Hello, I want to extract the words from a file which starts with SRD-R or SRD-DR. I have written a script which is able to trace the word but it is printing the whole line. sub extract_SRD_tag{ my ($tag, $app, $path, @data, $word ); $path = shift; $app = shift; open (FILE, $path) or... (2 Replies)
Discussion started by: suvendu4urs
2 Replies

6. Shell Programming and Scripting

data extraction from xml file

I have an of xml file as shown below <?xml version='1.0' encoding='ASCII' standalone='yes' ?> <Station Index="10264" > <Number Value="237895890" /> <Position Lat="-29.5" Lon="3.5" /> <MaxDepth Value="-4939" /> <VeloLines Count="24"> <VeloLine Index="0" > <Depth... (3 Replies)
Discussion started by: shashi792
3 Replies

7. Shell Programming and Scripting

Selective extraction of data from a files

Hi, I would like to seek for methods to do selective extraction of line froma file. The scenario as follows: I have a file with content: message a received on 11:10:00 file size: 10 bytes send by abc message b received on 11:20:00 file size: 10 bytes send by abc (3 Replies)
Discussion started by: dwgi32
3 Replies

8. Shell Programming and Scripting

Another data extraction question

Hi, I have a tmp file like below: <ADATA> ANUM=900 ADESC=Saving ATYP=0 TXREGD=0 </ADATA> <ADATA> ANUM=890 ADESC=Saving ATYP=0 ABAL=9000 TXREGD=1 </ADATA> <ADATA> (6 Replies)
Discussion started by: kunigirib
6 Replies

9. Shell Programming and Scripting

Data Extraction From a File

Hi All, I have a requirement where I have to search the file with some text say "Exception". This exception word can be repeated for more then 10 times. Suppose the "Exception" word is repeated at line numbers say x=10, 50, 60, 120. Now I want to extract all the lines starting from x-5 to... (3 Replies)
Discussion started by: rrangaraju
3 Replies

10. Shell Programming and Scripting

Data Extraction issue.

I have a small problem, I have written a following script, which extracts all the rows from source file which strats with T101 and rights it to another file mydata.dat Script my_script #!/bin/ksh YMONTH=$1 dir1='/home/data' dir2='/clients/source_file' cd $dir1 grep "T101"... (5 Replies)
Discussion started by: irehman
5 Replies
Login or Register to Ask a Question