Help with looping in shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with looping in shell scripting
# 8  
Old 01-08-2012
Try this...
Code:
echo $i | md5sum | grep -v ^000000 >> /home/ubuntu/Documents/log

--ahamed
# 9  
Old 01-08-2012
Quote:
Originally Posted by ahamed101
Try this...
Code:
echo $i | md5sum | grep -v ^000000 >> /home/ubuntu/Documents/log

--ahamed
Thanks will try it as soon as i get to a linux terminal... thanks a lot for the assistance!

---------- Post updated at 06:50 PM ---------- Previous update was at 06:34 PM ----------

Hi i tried your grep code, didnt work as planned.

in order to test i wrote this small code....
Code:
for i in $(seq -w 100000 100100)
do

echo $i | grep -v ^100088 >> /home/ubuntu/Documents/test_log

done

it didnt stop at 100088 but went all the way to 100100.

Last edited by Franklin52; 01-08-2012 at 09:26 AM..
# 10  
Old 01-08-2012
Hi.
Code:
       -m NUM, --max-count=NUM
              Stop reading a file after NUM matching lines ...

excerpt from man grep, q.v.

for GNU grep 2.5.3

Best wishes ... cheers, drl
# 11  
Old 01-08-2012
Quote:
Originally Posted by jremio
Thanks will try it as soon as i get to a linux terminal... thanks a lot for the assistance!

---------- Post updated at 06:50 PM ---------- Previous update was at 06:34 PM ----------

Hi i tried your grep code, didnt work as planned.

in order to test i wrote this small code....

for i in $(seq -w 100000 100100)
do

echo $i | grep -v ^100088 >> /home/ubuntu/Documents/test_log

done

it didnt stop at 100088 but went all the way to 100100.
The code provided wasn't supposed to stop there... Your request was not to include any hash strings starting with 0000...

--ahamed
# 12  
Old 01-08-2012
Hi.
Quote:
Originally Posted by ahamed101
The code provided wasn't supposed to stop there... Your request was not to include any hash strings starting with 0000...

--ahamed
He asked that question on post # 7:
Quote:
Originally Posted by jremio
I got one problem though, when the echo logs into the log file, is there any way to make it stop when one of the md5sum starts with 000000?
... cheers, drl
# 13  
Old 01-08-2012
this works for me:
Code:
for i in $( seq -w 0000 9999); 
do  
  hash=`echo $i | md5sum`; 
  echo $hash >> /tmp/somefile; 
  if [ `echo $hash|cut -c -4` == '0000' ]; 
  then 
    break; 
  fi;  
done;

However... it seams there are no hashes that start with four zeros.
You can verify this by changing the condition to:
Code:
if [ `echo $hash|cut -c -3` == '000' ];

or even removing the condition and then greping the output file for '^0000' (i.e. lines with four zeros at their beginning.

PS. Note that while this does work, it is not very efficient. As all the piping invokes subshels. 10Kiterations, with quite a few subshells in each iteration.... plenty of room for optimization. ;-)


Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 01-09-2012 at 03:28 AM.. Reason: Please use code tags for code and data samples, thank you
# 14  
Old 01-08-2012
Quote:
Originally Posted by azaria
this works for me:

for i in $( seq -w 0000 9999);
do
hash=`echo $i | md5sum`;
echo $hash >> /tmp/somefile;
if [ `echo $hash|cut -c -4` == '0000' ];
then
break;
fi;
done;

However... it seams there are no hashes that start with four zeros.
You can verify this by changing the condition to:
if [ `echo $hash|cut -c -3` == '000' ];

or even removing the condition and then greping the output file for '^0000' (i.e. lines with four zeros at their beginning.

PS. Note that while this does work, it is not very efficient. As all the piping invokes subshels. 10Kiterations, with quite a few subshells in each iteration.... plenty of room for optimization. ;-)
Thanks for the tip... thats exactly what I am using, it takes very long tho. u only see 0000 - 9999 here because its just for the proof of concept. Really wonder if theres anyway to make it faster by a whole lot...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell scripting looping issue

#!bin/ksh --------------------------------------------------------------------------------------------- -- Get sequence number from database --------------------------------------------------------------------------------------------- .os rm... (3 Replies)
Discussion started by: swathi reddy1
3 Replies

2. Shell Programming and Scripting

Simple looping in shell

Hii all. I have a problem with my shell script. This is my code while do space.exe inputs/gr$count >> outputs/t$count count=$ done I ussually work in cygwin. When i tried in linux(ubuntu, kali linux) i found error said Syntax error : end of file unexpected (expecting "do")... (6 Replies)
Discussion started by: weslyarfan
6 Replies

3. Shell Programming and Scripting

Looping not completing in shell script

Hi, Iam using below code to login to servers to get cpu utilisation. but output is coming for only one server. code is below root@blr-svr-oclan-01 # more SSSC_CPU_UTIL1.sh #!/bin/sh echo "CPU UTILIZATION" while read line; do IDLE=`/usr/local/bin/sshpass -p 'xxx' ssh xxx@$line 'sar 2 2' |... (1 Reply)
Discussion started by: surender reddy
1 Replies

4. Shell Programming and Scripting

C Shell Script: While function not fully looping

I am new to scripting and this is probably the 4th or 5th simple script I have written. I am working with a HUGE number of data that need to be organized into folders and named a certain way. I wrote the naming script using a while function to go through the 1000-some folders and rename the files... (0 Replies)
Discussion started by: notluckyhannah
0 Replies

5. Shell Programming and Scripting

[Solved] help me in this looping in shell scripting

Hi, #!/bin/ksh result='/TIA/app/UniQP/queue/document/CSB' i=0; while ; do i=`expr $i + 1` if ($i -lt 5);then echo "THerrFile_$i.err"; else break; fi done ... (0 Replies)
Discussion started by: sudhir_83k
0 Replies

6. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

7. Shell Programming and Scripting

Looping through a shell script with sql statements

Hello members, I'm working on the Solaris environment and the DB i'm using is Oracle 10g. Skeleton of what I'm attempting; Write a ksh script to perform the following. I have no idea how to include my sql query within a shell script and loop through the statements. Have therefore given a... (4 Replies)
Discussion started by: novice82
4 Replies

8. Shell Programming and Scripting

Convert shell script for looping

Situation: I have a working shell script on our file server (OSXS Tiger) to connect to a workstation, which is using a portable home directory (phd), and rsync a user's MirrorAgent.log. I'm not that strong of a scripter (obviously), but I would like to add other workstations to this script as they... (4 Replies)
Discussion started by: le0pard13
4 Replies

9. Shell Programming and Scripting

looping through a variable in a shell script

hi, my first question is :- i would like to know how do i loop through the output of a variable. for ex:- if i have a variable called x and echo $x gives the output like feb 19 07 feb 20 07 feb 21 07 i would like to know how do i loop through this since it is separated and i... (1 Reply)
Discussion started by: ramachandranrr
1 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question