LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-12-2014, 05:49 AM   #1
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Rep: Reputation: Disabled
Is something wrong with below code?


Hi,

Is something wrong with below code, actually i am getting value for only one variable.
Code:
VIP_RCV_SGL_FILE[52]='P0366'
VIP_RCV_SGL_FILE[53]='P1039'
VIP_RCV_SGL_FILE[54]='P1041'
VIP_RCV_SGL_FILE[55]='P1044'
VIP_RCV_SGL_FILE[56]='P1390'




for VIP_CUST_ID in "${VIP_RCV_SGL_FILE[@]}"
do
FILE_STATUS_NOTE=$(grep ${VIP_CUST_ID} "${SCHED_CONFIG}"|awk -F '|' '{ print $5 }')

FILES_RCVD=$(sed -n "/${VIP_CUST_ID}/,/<\/data_block>/p" "${RTVIEW}"|grep -A4 '${FILE_STATUS_NOTE}' "${RTVIEW}"|head -4|tail -1|tr '[<>]' ' '|awk -F ' ' '{print $2}')

FILES_WTNG=$(sed -n "/${VIP_CUST_ID}/,/<\/data_block>/p" "${RTVIEW}"|grep -A4 '${FILE_STATUS_NOTE}' "${RTVIEW}"|head -4|tail -1|awk -F ' ' '{print $2}')


FILES_EXCEPTION=$(sed -n "/${VIP_CUST_ID}/,/<\/data_block>/p" "${RTVIEW}"|grep -A4 '${FILE_STATUS_NOTE}' "${RTVIEW}"|head -4|tail -1|tr '[<>]' ' '|awk -F ' ' '{print $2}')

FILES_COUNT=$(sed -n "/${VIP_CUST_ID}/,/<\/data_block>/p" "${RTVIEW}"|grep -A4 '${FILE_STATUS_NOTE}' "${RTVIEW}"|head -2|tail -1|tr '[<>]' ' '|awk -F ' ' '{print $2}')
echo "FILE_STATUS_NOTE=${FILE_STATUS_NOTE}"
echo "FILES_RCVD=${FILES_RCVD}"
echo "FILES_WTNG=${FILES_WTNG}"
echo "FILES_EXCEPTION=${FILES_EXCEPTION}"
echo "FILES_COUNT=${FILES_COUNT}"
echo "---------------------------"
done
output:
FILE_STATUS_NOTE=BMS - Expected 2 files between 03:00 - 04:30
FILES_RCVD=
FILES_WTNG=
FILES_EXCEPTION=
FILES_COUNT=
 
Old 03-12-2014, 05:52 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,258

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
1. set it to use bash
Code:
#!/bin/bash

# and use this to see what's really happening
set -xv

<your code here>
I'd also go one line at a time if you don't see the soln quickly.
 
Old 03-12-2014, 05:58 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,501

Rep: Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431
I would simplify those sed|grep|head|tail|tr|awk chains, usually you can implement it in awk using only a few line of codes.
It will also speed up that loop
 
Old 03-12-2014, 07:10 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
I am with pan64, especially if you use the exact same line to be stored in 2 different variables:
Code:
FILES_RCVD=$(     sed -n "/${VIP_CUST_ID}/,/<\/data_block>/p" "${RTVIEW}"|grep -A4 '${FILE_STATUS_NOTE}' "${RTVIEW}"|head -4|tail -1|tr '[<>]' ' '|awk -F ' ' '{print $2}')
FILES_EXCEPTION=$(sed -n "/${VIP_CUST_ID}/,/<\/data_block>/p" "${RTVIEW}"|grep -A4 '${FILE_STATUS_NOTE}' "${RTVIEW}"|head -4|tail -1|tr '[<>]' ' '|awk -F ' ' '{print $2}')
The spaces I placed in the first are superfluous to the output, but I cannot see any difference between these 2 lines except the variables they are assigned to.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What wrong in this code kits Programming 10 01-10-2007 04:55 AM
anything wrong with this code? bytez Linux - Software 1 09-19-2006 05:52 AM
What is wrong with the following C code? indian Programming 17 12-04-2005 10:01 AM
What is wrong with this c code? schatoor Programming 3 06-02-2005 11:04 AM
What is wrong with this C code ? indian Programming 8 04-16-2005 05:42 AM


All times are GMT -5. The time now is 04:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration