Help in extracting fields from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in extracting fields from a file
# 43  
Old 11-23-2011
Quote:
Originally Posted by ahamed101
Try the -s option...
Code:
sqlplus -s /nolog << EOF
...

To remove the SQL query from output.txt
Code:
sed -i '/^SQL/d' output.txt

--ahamed
It worked fine with the output file,but the messages are still appearing over the screen
the code used is :
Code:
#!/bin/ksh
db_user=$DB_USER_NAME
db_pwd=$DB_PASSWORD
db_sid=$TWO_TASK
if [ $# -ne 1 ]; then
echo "\tUsage: MoveUsageProcessing <BC Log file Name>"
exit 1
else
BCLogFileName=$1
fi
grep -i  'MoveUsage daemon needs to run on this account before it can be billed'  $1 |awk -F\| '{for(i=0;++i<=NF;) if($i ~ /Acct/) print substr($i,6)}' > ./$1.txt
echo " log file path is : './$1.txt' ";


while read var_ack_party_name
do
sqlplus -s  /nolog << EOF
    connect $db_user/$db_pwd@$db_sid;
    SPOOL output.txt;
    set pagesize 0 feedback off verify off heading off echo off linesize 100 
    select *  from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and event_data_text like '%$var_ack_party_name%';
    SPOOL OFF;
    EXIT;
EOF
sleep 1
done < $1.txt
nawk '/SQL/{next}{if($2 ~ "^[a-zA-Z]"){print $1,substr($3,length($3),1)}}'  ./output.txt | while read a b
do
echo $a
echo $b 
MoveUsageDaemon -r $b -i $b -e $a -p 1
done

the output displayed over the screen is:
Code:
 log file path is : './20111011.71BC.LOG.txt' 
           203969 OrdAcctCycChg                            MOVE_USAGE_DAEMON1
20101001 07091693 BILLING_CYCLE_CHANGE                              2 SKORUKON
20101001 07092076 ACCT_NBR|0030063224|prev_CYCLE_CD|VA|new_CYCLE_CD|27|ACCT_CYCLE_EFF_DT|20101001|
07092076 20101001                           P

           204001 OrdAcctCycChg                            MOVE_USAGE_DAEMON1
20101001 07181709 BILLING_CYCLE_CHANGE                              2 SKORUKON
20101001 07182021 ACCT_NBR|0030063224|prev_CYCLE_CD|27|new_CYCLE_CD|VA|ACCT_CYCLE_EFF_DT|20101027|
07182021 20101001                           P

203969
1
204001
1

the contents of output file is fine,
output.txt contents are:
Code:
more output.txt
           203969 OrdAcctCycChg                            MOVE_USAGE_DAEMON1                       
20101001 07091693 BILLING_CYCLE_CHANGE                              2 SKORUKON                      
20101001 07092076 ACCT_NBR|0030063224|prev_CYCLE_CD|VA|new_CYCLE_CD|27|ACCT_CYCLE_EFF_DT|20101001|  
07092076 20101001                           P                                                       
                                                                                                    
           204001 OrdAcctCycChg                            MOVE_USAGE_DAEMON1                       
20101001 07181709 BILLING_CYCLE_CHANGE                              2 SKORUKON                      
20101001 07182021 ACCT_NBR|0030063224|prev_CYCLE_CD|27|new_CYCLE_CD|VA|ACCT_CYCLE_EFF_DT|20101027|  
07182021 20101001

# 44  
Old 11-23-2011
Might not be a good method, but try this...
Code:
ret=`sqlplus -s  /nolog << EOF
...
EOF`

--ahamed
# 45  
Old 11-23-2011
Quote:
Originally Posted by ahamed101
Might not be a good method, but try this...
Code:
ret=`sqlplus -s  /nolog << EOF
...
EOF`

--ahamed
it is throwing this error:
[B]
ew1.ksh[17]: ret: not found
[B]

code I have used:
Code:
#!/bin/ksh
db_user=$DB_USER_NAME
db_pwd=$DB_PASSWORD
db_sid=$TWO_TASK
if [ $# -ne 1 ]; then
echo "\tUsage: MoveUsageProcessing <BC Log file Name>"
exit 1
else
BCLogFileName=$1
fi
grep -i  'MoveUsage daemon needs to run on this account before it can be billed'  $1 |awk -F\| '{for(i=0;++i<=NF;) if($i ~ /Acct/) print substr($i,6)}' > ./$1.txt
echo " log file path is : './$1.txt' ";


while read var_ack_party_name
do
ret = 'sqlplus -s  /nolog << EOF
    connect $db_user/$db_pwd@$db_sid;
    SPOOL output.txt;
    set pagesize 0 feedback off verify off heading off echo off linesize 100 
    select *  from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and event_data_text like '%$var_ack_party_name%';
    SPOOL OFF;
    EXIT;
EOF'
sleep 1
done < $1.txt
nawk '/SQL/{next}{if($2 ~ "^[a-zA-Z]"){print $1,substr($3,length($3),1)}}'  ./output.txt | while read a b
do
echo $a
echo $b 
MoveUsageDaemon -r $b -i $b -e $a -p 1
done

# 46  
Old 11-23-2011
no space between ret = and ` ret=`...`
And they are backticks not single quotes!

--ahamed
# 47  
Old 11-23-2011
Quote:
Originally Posted by ahamed101
no space between ret = and ` ret=`...`
And they are backticks not single quotes!

--ahamed
Tried with the one you mentioned,it succeeded but thrown a not found error msg:
Code:
 new1.ksh 20111011.71BC.LOG
 log file path is : './20111011.71BC.LOG.txt' 
new1.ksh[17]: ret:  not found
203969
1
204001
1

# 48  
Old 11-23-2011
Can you paste that piece of code alone?
--ahamed
# 49  
Old 11-23-2011
Quote:
Originally Posted by ahamed101
Can you paste that piece of code alone?
--ahamed
Code:
#!/bin/ksh
db_user=$DB_USER_NAME
db_pwd=$DB_PASSWORD
db_sid=$TWO_TASK
if [ $# -ne 1 ]; then
echo "\tUsage: MoveUsageProcessing <BC Log file Name>"
exit 1
else
BCLogFileName=$1
fi
grep -i  'MoveUsage daemon needs to run on this account before it can be billed'  $1 |awk -F\| '{for(i=0;++i<=NF;) if($i ~ /Acct/) print substr($i,6)}' > ./$1.txt
echo " log file path is : './$1.txt' ";


while read var_ack_party_name
do
ret =`sqlplus -s  /nolog << EOF
    connect $db_user/$db_pwd@$db_sid;
    SPOOL output.txt;
    set pagesize 0 feedback off verify off heading off echo off linesize 100 
    select *  from bus_event where ack_party_name like 'MOVE_USAGE_DAEMON%' and event_data_text like '%$var_ack_party_name%';
    SPOOL OFF;
    EXIT;
EOF`
sleep 1
done < $1.txt
nawk '/SQL/{next}{if($2 ~ "^[a-zA-Z]"){print $1,substr($3,length($3),1)}}'  ./output.txt | while read a b
do
echo $a
echo $b 
MoveUsageDaemon -r $b -i $b -e $a -p 1
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extracting specific fields from an XML file

Hello All, I have a requirement to split the input.xml file different files and i have tried using earlier examples(where i have posted in the forum), but still no luck Here is my input.xml <jms-system-resource> <name>UMSJMSSystemResource</name> ... (4 Replies)
Discussion started by: Siv51427882
4 Replies

2. Shell Programming and Scripting

UNIX extracting fields

I have one file A.txt which is comma separated and I want to extract first 4 field's in a file and also I want to add one more column in output A.txt in output for all records. A.txt should not be hard coded since I do not filename it may be any file. (1 Reply)
Discussion started by: vamsi.valiveti
1 Replies

3. Shell Programming and Scripting

need help in writing a script for extracting fields

Hi, I need to extract last character of the field retrieved from the database using select command. eg: select event,text from event_data; o/p: Event1,text1 But I need to extract only '1' from the fields...similarly '2' from Event2,text2 and '3' from Event3,text3 etc., and need to pass... (6 Replies)
Discussion started by: Rajesh Putnala
6 Replies

4. Shell Programming and Scripting

Extracting Some fields from current file to another file

Hi, I have multiple files in a directory all I am trying to do is to read the files in the directory and extract data from 2nd field till 10th field and put it in a new files. The files are pipe delimited. The new file will have the same name as the old file but the prefix of PRE_oldfilename. ... (1 Reply)
Discussion started by: simi28
1 Replies

5. Shell Programming and Scripting

Extracting fields from file

I am need to extract a number of values from a file, put have now clue how to do this. The file looks like this: # My file Dest=87;CompatibleSystemSoftwareVersion=2.5300-; Dest=87;ImageVersion=000061f3;SystemSoftwareVersion=2.5300;CDN=http://my.backup.com/download.txt;CDN_Timeout=30; I... (3 Replies)
Discussion started by: MagicDude4Eva
3 Replies

6. Shell Programming and Scripting

Removing LF and extracting two fields

I need some assistance, I am writing a script in bash. I want to do two things: 1/. I want to replace the LF at the end of the RFH  Ø  ¸MQSTR ¸ so I can process the file record by record using a while loop. 2/. I want to extract two fields from each record, they are identified with... (1 Reply)
Discussion started by: gugs
1 Replies

7. Shell Programming and Scripting

Extracting records with unique fields from a fixed width txt file

Greetings, I would like to extract records from a fixed width text file that have unique field elements. Data is structured like this: John A Smith NY Mary C Jones WA Adam J Clark PA Mary Jones WA Fieldname / start-end position Firstname 1-10... (8 Replies)
Discussion started by: sitney
8 Replies

8. Shell Programming and Scripting

extracting fields

Hi, i have a line with several fields (indefinite number of - count varies) separated by colon. Now, i need to pick each field (except the first one) and have it assigned to variable within a loop. In other words, in the first iteration of the loop, the variable must be assigned with 2nd... (2 Replies)
Discussion started by: prvnrk
2 Replies

9. UNIX for Dummies Questions & Answers

Extracting information from text fields.

Dear friends, I'm a novice Unix user and I'm trying to learn the ropes. I have a big task I have to accomplish and I'm convinced Unix can get the job done, I just haven't figured out how. I recently posted on the topic of cutting text between unique text patterns and somebody helped me a great... (24 Replies)
Discussion started by: spindoctor
24 Replies

10. Shell Programming and Scripting

Extracting fields from an output 8-)

I am getting a variable as x=2006/01/18 now I have to extract each field from it. Like x1=2006, x2=01 and x3=18. Any idea how? Thanks a lot for help. Thanks CSaha (6 Replies)
Discussion started by: csaha
6 Replies
Login or Register to Ask a Question