Getting file count in a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting file count in a variable
# 15  
Old 05-27-2014
Here is the output from ls /temp/sample_*|od -cb


Code:
0000000    /   t   e   m   p   /   s   a   m   p   l   e   _   a   a   _   t
         057 164  145 155 160 057 163 141 155 160 154 145 137 141 141 137 164
0000020    e   s   t  \n   /   t   e    m   p   /   s   a   m   p   l   e   _
         145 163 164 012 057 164  145  155 160 057 163 141 155 160 154 145 137
0000040    b   b   _   t   e   s   t  \n   /   t   e   m   p   /   s   a   m
         142 142 137 164 145 163 164 012 057 164  145 155 160 057 163 141 155
0000060    p   l   e   _   c   c   _   t   e   s   t  \n   /   t   e   m   p
         160 154 145 137 143 143 137 164 145 163 164 012 057 164  145 155 160
0000100    /   s   a   m   p   l   e   _   d   d   _   t   e   s   t  \n
         057 163 141 155 160 154 145 137 144 144 137 164 145 163 164 012
0000120

Pls let me know what can be inferred from the above
# 16  
Old 05-27-2014
Quote:
Originally Posted by swasid
Here is the output from ls /temp/sample_*|od -cb


Code:
0000000    /   t   e   m   p   /   s   a   m   p   l   e   _   a   a   _   t
         057 164  145 155 160 057 163 141 155 160 154 145 137 141 141 137 164
0000020    e   s   t  \n   /   t   e    m   p   /   s   a   m   p   l   e   _
         145 163 164 012 057 164  145  155 160 057 163 141 155 160 154 145 137
0000040    b   b   _   t   e   s   t  \n   /   t   e   m   p   /   s   a   m
         142 142 137 164 145 163 164 012 057 164  145 155 160 057 163 141 155
0000060    p   l   e   _   c   c   _   t   e   s   t  \n   /   t   e   m   p
         160 154 145 137 143 143 137 164 145 163 164 012 057 164  145 155 160
0000100    /   s   a   m   p   l   e   _   d   d   _   t   e   s   t  \n
         057 163 141 155 160 154 145 137 144 144 137 164 145 163 164 012
0000120

Pls let me know what can be inferred from the above
We have now determined that there are no spaces, tabs, or carriage return characters at the ends of the filenames and that there are no embedded control characters in the middle of the filenames.

What operating system are you using?

What shell are you using?

What do you get when you run the updated script:
Code:
#!/bin/ksh
set -xv
cd /temp    # This was actually /tmp
fcnt=0
for i in aa bb cc dd
do      if [ -e "sample_${i}_test" ]
        then    fcnt=$((fcnt + 1))
        else    echo "sample_${i}_test missing"
        fi
done
if [ $fcnt -eq 4 ]
then    echo "There are $fcnt files present in /temp"
else    echo "There are only $fcnt files present in /temp; try again later."
        exit 1
fi
echo 'Continue processing...'

What did you mean by the comment shown in red above? Are these files in /temp or in /tmp?
# 17  
Old 05-27-2014
I am using Korn Shell and running this on AIX 5.3. The files are under /temp (created for the purpose of testing) itself
# 18  
Old 05-27-2014
Quote:
Originally Posted by swasid
I am using Korn Shell and running this on AIX 5.3. The files are under /temp (created for the purpose of testing) itself
I repeat, please run the updated script shown in post #16 in this thread and show us the output. We need to see the trace output to figure out what is going on.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk variable search and line count between variable-search pattern

Input: |Running the Rsync|Sun Oct 16 22:48:01 BST 2016 |End of the Rsync|Sun Oct 16 22:49:54 BST 2016 |Running the Rsync|Sun Oct 16 22:54:01 BST 2016 |End of the Rsync|Sun Oct 16 22:55:45 BST 2016 |Running the Rsync|Sun Oct 16 23:00:02 BST 2016 |End of the Rsync|Sun Oct 16 23:01:44 BST 2016... (4 Replies)
Discussion started by: busyboy
4 Replies

2. UNIX for Dummies Questions & Answers

To count total of specific character in a file and save its value to a variable

Hi all, I have a file that contains characters. How do I get total of spesific character from that file and save the count to a variable for doing for calculation. data.txt 1 2 2 2 2 3 3 4 5 6 7 8 5 4 3 4 (5 Replies)
Discussion started by: weslyarfan
5 Replies

3. Shell Programming and Scripting

count lines in file to variable

I have a text file in which you need to identify the number of lines that looks like this: awk '{x + +} END {print x}' filename The problem is that I do not know how this data to any variable in which then need to continue to work in a cycle for .. do not know someone help? Sorry for my... (4 Replies)
Discussion started by: gizmo16
4 Replies

4. UNIX for Dummies Questions & Answers

How to set a variable with a count variable i.e. VARIABLE$COUNT

Hi All I've very nearly finished this script I'm working on but have hit another idiots problem, after googling I can't see a solution for this one. I have a while count loop that checks checks two consecutive values then increments the count by two. What the script has to do is then check... (5 Replies)
Discussion started by: Bashingaway
5 Replies

5. Shell Programming and Scripting

To count a string with in a variable

I am writing a ksh to check for duplicate records in two different set of tables on oracle database, to get this i am running two plsql qurries at a time through the ksh, so the output of the qurries will be stored in variable say "SQL_STRING". So now to say if duplicate records exists in table or... (6 Replies)
Discussion started by: vpv0002
6 Replies

6. Shell Programming and Scripting

count of a string within a variable

I am writing ksh to check for duplicate records in two different set of tables on oracle database, to get this i am running two plsql qurries at a time through the ksh, so the output of the qurries will be stored in variable say "SQL_STRING". So now to say if duplicate records exists in table or... (3 Replies)
Discussion started by: vpv0002
3 Replies

7. Shell Programming and Scripting

Getting Sum, Count and Distinct Count of a file

Hi all this is a UNIX question. I have a large flat file with millions of records. col1|col2|col3 1|a|b 2|c|d 3|e|f 3|g|h footer**** I am supposed to calculate the sum of col1 1+2+3+3=9, count of col1 1,2,3,3=4, and distinct count of col1 1,2,3=c3 I would like it if you avoid... (4 Replies)
Discussion started by: singhabhijit
4 Replies

8. UNIX for Dummies Questions & Answers

How to count the record count in an EBCDIC file.

How do I get the record count in an EBCDIC file on a Linux Box. :confused: (1 Reply)
Discussion started by: oracle8
1 Replies

9. Shell Programming and Scripting

setting file count to a variable

Hey guys. My goal here is to count the number of .dat files in in a directory(28 files). If 28 files exist I am ok. Having trouble doing this. Any help would b e greatly appreciated. #!/usr/bin/ksh #============================================================================= ### Define local... (3 Replies)
Discussion started by: ecupirate1998
3 Replies

10. Shell Programming and Scripting

select count(*) into a variable

Hi, Could anybody help me how can I assign the value of "select count(*) from table1" to a variable in an unix shell script. Thanks. (4 Replies)
Discussion started by: nguda
4 Replies
Login or Register to Ask a Question