Sponsored Content
Top Forums Shell Programming and Scripting some strange problem with return data in script Post 302587124 by sukhdip on Wednesday 4th of January 2012 06:17:08 AM
Old 01-04-2012
some strange problem with return data in script

Hi,
I have come across a little strange problem in my script. i tried the same logic in some other script where its working fine. but in other script its not behaving as expected.
Here is the code:
Code:
#!/bin/bash

run_count="2"    
catalog_name="demo"
cd /root/Test_project/Files/$catalog_name
for file in $run_count"_"*.csv; do
 echo $file
 file_count=`grep -c "." $file`
 echo $file_count"file_count \n"
 FILE_NAME=$run_count"_"$catalog_name"_Row_Count.prop"
 PROP_KEY=$file
 Count_file=$(awk -F"=" '{ ()print $1; }' $FILE_NAME )
 echo "file count= "$Count_file
 Count=`cat ${FILE_NAME} | grep ${PROP_KEY} | cut -d'=' -f2`

 echo $Count  #[Here its working fine, its showing the correct values which is returned from top]
 echo $Count"hi" #[here if i'm printing something with it then the value of $Count is lost. and its only printing hi] don't know why
 
#and based on that furhter logic is not working which is under if

if [ "$Count" == "$file_count" ]; then
 echo "column header count row proper"
 else
 echo "Error send a mail as count is not correct in "$file
 exit 1
fi
done
exit 0

My question is this
1. Why the value is lost of $Count when am trying to print something with it.
2. Is there any problem of data type?
3. What type of datatype is returned by cut command in above?
Here I need to return integer and then to compare them
Count is the number of files, which is specified in a property file from where its picking in above case.
file_count is number of rows in a file.

I need to compare them both and then have to take action further.
Help me out if there is something wrong with data type or logic or something else.

Thanks,
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Strange Problem

I did an installation of Redhat 7.1 and it seem to install smoothly. I go and reboot and I get the following message: "INIT: Id "x" respawing too fast: disabled for 5 minutes" The screen flashes 4 times every 10 seconds or so. I can't seem to figure why this does this. It might be a simple... (2 Replies)
Discussion started by: forjohnny
2 Replies

2. Linux

very strange problem

I have installed Fedora Core on a Toshiba Satellite Pro4600 laptop recently I have experienced a rather mysterious problem if I touch anything specially the keyboard or mouse I see this stuff “67yujhnmyyy” straight away some time it won't stop for while like this... (5 Replies)
Discussion started by: kemobyte
5 Replies

3. Shell Programming and Scripting

Perl script strange problem

Hi All, I have one strange problem in perl script. Bellow is the contents of the script i am trying to write: #!/usr/local/bin/perl my $module_list = ''; my @running_module; my $count=0; my $flag=0; my $ccprojecthome=$ENV{CCPROJECTHOME}; @module_list = `cat... (2 Replies)
Discussion started by: vaibhav
2 Replies

4. Shell Programming and Scripting

How to use substr to return data into a shell script variable?

I'm writing a shell script in which I need to be able to pull a portion of the file name out. I'm testing with the following code: x="O1164885.DAT" y=`ls -ltr *${x}|awk '{print substr($0,3)}'` echo ${x}|awk '{print substr($0,3)}' echo "y="$y I can echo it to the screen just fine but I... (3 Replies)
Discussion started by: ttunell
3 Replies

5. Shell Programming and Scripting

Strange problem.

Well, my script started off to do what i wanted. Now, i think its not recognizing the pattern so its not moving anything. What i have to do is execute my script command for the move to take effect. So i did that and yayy it worked. Strange thing is that my DESTDIR was empty to begin with.... (2 Replies)
Discussion started by: oxoxo
2 Replies

6. Shell Programming and Scripting

Problem - script that parses $date data...

This is probably archaic, but I'm new to unix and this is my first shell script. I'm writing this script to use in another script. All I am trying to do is make the parts of the output from date usable in my other script. I was wondering if you could stand looking at this and see if you notice... (8 Replies)
Discussion started by: Dalcron
8 Replies

7. Shell Programming and Scripting

Strange Problem

Hi All, I am encountering an unexpected problem while running my process, using daemon placed in /etc/init.d/. I have a process that is opening shared library using dlopen. When I run my process on the command line, it is able to open the library. But when I used daemon to run my process, I... (0 Replies)
Discussion started by: qwerty-1
0 Replies

8. Shell Programming and Scripting

Script problem with deleting data

The 10.Delete data doesnt work at all, plesase anyone could help on that. When I choose options 10 to delete a record it only copy the selected data on the other file dbs1 but doesnt delete it from the database where other records are. #! /bin/bash i="y" echo "Enter name of database " read db... (6 Replies)
Discussion started by: Lina_14
6 Replies

9. Shell Programming and Scripting

Strange problem with shell script commands

i have a very strange problem.....i gave the following command on the terminal sed '15 w temp' f1 -n | temp1=$(awk '{printf $3}' temp) | sed '/'$temp1'/s/1.330000/1.232032/' f1 > f10 where f1, temp and f10 are filenames. This works sometimes and the same command doesn't work sometimes.... (2 Replies)
Discussion started by: Agastya
2 Replies

10. Shell Programming and Scripting

Return: can only `return' from a function or sourced script

Not sure where the problem is. I can run the script without any issue using the following command. . /opt/app/scripts/cdc_migration.sh But it fails with the below error when I try it this way /opt/app/scripts/cdc_migration.sh /opt/app/scripts/cdc_migration.sh: line 65: return: can only... (1 Reply)
Discussion started by: svajhala
1 Replies
GC(1)							      General Commands Manual							     GC(1)

NAME
gc - count graph components SYNOPSIS
gc [ -necCaDUrs? ] [ files ] DESCRIPTION
gc is a graph analogue to wc in that it prints to standard output the number of nodes, edges, connected components or clusters contained in the input files. It also prints a total count for all graphs if more than one graph is given. OPTIONS
The following options are supported: -n Count nodes. -e Count edges. -c Count connected components. -C Count clusters. By definition, a cluster is a graph or subgraph whose name begins with "cluster". -a Count all. Equivalent to -encC -r Recursively analyze subgraphs. -s Print no output. Only exit value is important. -D Only analyze directed graphs. -U Only analyze undirected graphs. -? Print usage information. By default, gc returns the number of nodes and edges. OPERANDS
The following operand is supported: files Names of files containing 1 or more graphs in dot format. If no files operand is specified, the standard input will be used. EXIT STATUS
The following exit values are returned: 0 Successful completion. 1 The -U or -E option was used, and a graph of the wrong type was encountered. AUTHOR
Emden R. Gansner <erg@research.att.com> SEE ALSO
wc(1), acyclic(1), gvpr(1), gvcolor(1), ccomps(1), sccmap(1), tred(1), libgraph(3) 21 March 2001 GC(1)
All times are GMT -4. The time now is 09:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy