Problem with grep on aix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with grep on aix
# 1  
Old 01-30-2012
Problem with grep on aix

Hi..
I am facing a strange problem on AIX with ksh scripting.
The problem is with grep command. It's not able to work in the below code.

Code:
#!/bin/ksh

run_count=1
catalog_name="rrc"
cd /Dataload_Scripts/Files/$catalog_name
#file=""
for file in $run_count"_"*.csv; do
 echo $file

 # Getting row count from property file
 FILE_NAME=$run_count"_"$catalog_name"_Record_Count.txt"
 echo "FILE_NAME " $FILE_NAME
 PROP_KEY=$file
 echo "PROP_KEY" $PROP_KEY
 RowCount_from_prop=$(cat ${FILE_NAME} | grep "${PROP_KEY}" | cut -d'=' -f2 | tr -d '\r')
 echo "RowCount_from_prop" $RowCount_from_prop
 
 # Get row count from csv file
 RowCount_from_csv=$(awk 'END { print NR-1 }' $file)
 echo "RowCount_from_csv= "$RowCount_from_csv

 if [ "$RowCount_from_csv" == "$RowCount_from_prop" ]
 then
  echo "column header count row proper"
 else
  echo "column header count not correct in " $file
  ret_flag=1
 fi
done
if [ $ret_flag -eq 1 ]; then
 echo "exiting with errors"
 exit 1
else
 exit 0
fi

I'm not able to get value in RowCount_from_prop. echo is showing only blanks upto cat command its working fine. but at grep dunno whats happening.
Code:
1_rrc_attribute.csv
FILE_NAME  1_rrc_Record_Count.txt
PROP_KEY 1_rrc_attribute.csv
RowCount_from_prop
RowCount_from_csv= 203
column header count not correct in  1_rrc_attribute.csv

# 2  
Old 01-30-2012
Please post the output from this command set. It is designed to find out if the basic grep finds the value and then to display the result with control codes visible.
Code:
cat 1_rrc_Record_Count.txt| grep "1_rrc_attribute.csv" | sed -n l

If you get no output, please post the output from:
Code:
cat 1_rrc_Record_Count.txt | sed -n l

I think that on your thread last week people were also asking to see the input data.


Ps. On my ksh, this "==" is a syntax errror.
Quote:
if [ "$RowCount_from_csv" == "$RowCount_from_prop" ]
# 3  
Old 01-30-2012
why
Code:
RowCount_from_prop=$(cat ${FILE_NAME} | grep "${PROP_KEY}" | cut -d'=' -f2 | tr -d '\r')

and not
Code:
RowCount_from_prop=$(cat $FILE_NAME | grep "$PROP_KEY" | cut -d'=' -f2 | tr -d '\r')

?
# 4  
Old 01-31-2012
Quote:
Originally Posted by vbe
why
Code:
RowCount_from_prop=$(cat ${FILE_NAME} | grep "${PROP_KEY}" | cut -d'=' -f2 | tr -d '\r')

and not
Code:
RowCount_from_prop=$(cat $FILE_NAME | grep "$PROP_KEY" | cut -d'=' -f2 | tr -d '\r')

?
@vbe I tried your way. But result remains the same. no changes in the out put.Smilie
@methyl I'm trying with that will post the output.
ANY other solution as if alternate for grep command.Smilie
# 5  
Old 01-31-2012
Quote:
Originally Posted by sukhdip
Hi..
I am facing a strange problem on AIX with ksh scripting.
The problem is with grep command. It's not able to work in the below code.

Code:
#!/bin/ksh
 
run_count=1
catalog_name="rrc"
cd /Dataload_Scripts/Files/$catalog_name
#file=""
for file in $run_count"_"*.csv; do
 echo $file
 
 # Getting row count from property file
 FILE_NAME=$run_count"_"$catalog_name"_Record_Count.txt"
 echo "FILE_NAME " $FILE_NAME
 PROP_KEY=$file
 echo "PROP_KEY" $PROP_KEY
 RowCount_from_prop=$(cat ${FILE_NAME} | grep "${PROP_KEY}" | cut -d'=' -f2 | tr -d '\r')
 echo "RowCount_from_prop" $RowCount_from_prop
 
 # Get row count from csv file
 RowCount_from_csv=$(awk 'END { print NR-1 }' $file)
 echo "RowCount_from_csv= "$RowCount_from_csv
 
 if [ "$RowCount_from_csv" == "$RowCount_from_prop" ]
 then
  echo "column header count row proper"
 else
  echo "column header count not correct in " $file
  ret_flag=1
 fi
done
if [ $ret_flag -eq 1 ]; then
 echo "exiting with errors"
 exit 1
else
 exit 0
fi

I'm not able to get value in RowCount_from_prop. echo is showing only blanks Image upto cat command its working fine. but at grep dunno whats happening.
Code:
1_rrc_attribute.csv
FILE_NAME  1_rrc_Record_Count.txt
PROP_KEY 1_rrc_attribute.csv
RowCount_from_prop
RowCount_from_csv= 203
column header count not correct in  1_rrc_attribute.csv


The way I look at your script, to me it seems that FILE_NAME 1_rrc_Record_Count.txt should contain 1_rrc_attribute.csv as data...

But just for the sake of making life easier, can we actually see the content of the file 1_rrc_Record_Count.txt and 1_rrc_attribute.csv ...
# 6  
Old 01-31-2012
Hi..and Thanks all for your valuable replies to the thread.
Problem is solved. Problem lies with the input i.e., 1_rrc_Record_Count.txt file.

Thanks once again. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Need grep -v Equivalent for AIX

Need grep -v "Hello" equivalent for AIX (9 Replies)
Discussion started by: mohtashims
9 Replies

2. UNIX for Dummies Questions & Answers

sed Or Grep Problem OR Terminal Problem?

I don't know if you guys get this problem sometimes at Terminal but I had been having this problem since yesterday :( Maybe I overdid the Terminal. Even the codes that used to work doesn't work anymore. Here is what 's happening: * I wanted to remove lines containing digits so I used this... (25 Replies)
Discussion started by: Nexeu
25 Replies

3. AIX

How to grep PID and program name from netstat in AIX?

Hi All, I am using netstat on AIX to grep info on all open connections. However, unlike on Linux(Centos), I do not get the PID and program name using netstat on AIX. I need this info to be clubbed along with the information retrieved using netstat version of AIX. Is there a way this can be... (1 Reply)
Discussion started by: Vipin Batra
1 Replies

4. AIX

AIX 6.1 reach the threshold of stream(no -a|grep strthresh)

last night i want to do oracle full backup with expdp when i switch to oracle it hangs,it looks like: su - oracle there is nothing feedback and hang ,but su - root work fine. then i use truss su - oracle found it stuck at "ENOSR" ,then i changed the kernel parameter of strthresh from 85 to 90... (7 Replies)
Discussion started by: machinen
7 Replies

5. Shell Programming and Scripting

aix :grep to get lines before and after string

am using AIX and I have a string "There is no process to read data written to a pipe". I want to get the output 2 lines before and 4 lines after this string. The string is present like more than 100 times in the log and I want to output, the last result in the log with this string I tried using... (1 Reply)
Discussion started by: PhAnT0M
1 Replies

6. AIX

Grep last 5 mins from log file in AIX

I want to grep only last 5 mins of a log file in bash I have a syslog which contains the following Mon Jul 11 20:47:42 Mon Jul 11 20:47:52 The following works in Unix but not in AIX . Please can you let me know as to what would be the AIX equivalent Code: for (( i = 5; i >=0;... (1 Reply)
Discussion started by: necro98
1 Replies

7. AIX

AIX OS problem? network problem?

Dear ALL. I installed AIX OS on customer sites. but Only one site is too slow when I connected telnet, ftp.. Ping is too fast. but telnet and FTP is not connected.. of course i check the configuration file on aix but it's normal. Do any Idea?? thanks in advance. - Jun - (3 Replies)
Discussion started by: Jeon Jun Seok
3 Replies

8. AIX

AIX 4.2 Korn shell and grep question

Ho do I find out the verion of the Kron shell on my client`s system ? There is no one to ask. They are not knowledged enough (hard to believe but yes). Also, on that AIX 4.2, I am trying to figure out how to do a grep using a search patter like below but does not seam to work. The '*' do... (11 Replies)
Discussion started by: Browser_ice
11 Replies

9. UNIX for Advanced & Expert Users

AIX 5.2 problem

Hello, I'm working on a AIX5.2 OS. The problem i'm facing is that the system performance is good in rrot login, but when i switch to other users login it is very slow. A ls or even pwd command take almost 20 to 30 sec to disply output. The same logins are working fine on other... (2 Replies)
Discussion started by: pradeepmacha
2 Replies

10. AIX

AIX pg problem

Hi all, I have problem with regards to using pg on AIX v5.3.0.0 . Here wht i am trying to do --- i have shell script with the following statements if || then echo ^[[?3h tput clear pg -f $1$2 echo ^[[?3l ... (0 Replies)
Discussion started by: ramanujapuram
0 Replies
Login or Register to Ask a Question