how to use loops to take the values line by line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to use loops to take the values line by line
# 1  
Old 08-14-2012
Java how to use loops to take the values line by line

Hi am using aix ...
I have tried so far but am getting unknown test operator error

for example i have three files in one dir ...
Code:
A2008
A2408
A2808

final output results should be A0108 is missing
---
Code:
A1908 is missing
A2108 is missing
.....

Code:
#! /bin/ksh
i=`ls A* |cut -c2-3`
j=`date +%m`
while [ $i -le 30 -o $i -eq 31 ] //$i is taking three values 20 24 28 (in this wants to check individually )
do
  if [ ! -f A$i$j ]
  then
    echo A${i}${j} is missing
  fi
  i=`expr $i + 1`
done


Last edited by Scott; 08-14-2012 at 05:56 AM.. Reason: Please use code tags and less formatting
# 2  
Old 08-14-2012
You can use for loop to get the values stored in $i.

something like this should help:

Code:
for k in $i
do
    echo $k
done

# 3  
Old 08-14-2012
thanks arun ..
am getting an error as
Code:
[ 20 24 28 -le 30 -o 20 24 28 -eq 31 ]
aa02[7]: 24: unknown test operator
[ 20 24 28 -le 30 -o 20 24 28 -eq 31 ]
aa02[7]: 24: unknown test operator
[ 20 24 28 -le 30 -o 20 24 28 -eq 31 ]
aa02[7]: 24: unknown test operator


Last edited by zaxxon; 08-14-2012 at 05:56 AM.. Reason: code tags
# 4  
Old 08-14-2012
Code:
#! /bin/ksh
i=`ls A* |cut -c2-3`
j=`date +%m`

for k in $i 
do
     if [ ! -f A$k$j ]
     then
           echo A${k}${j} is missing
      fi
done

Hope this meets your requirement..

---------- Post updated at 02:15 PM ---------- Previous update was at 01:29 PM ----------

Btw I just tried to fix the error, your logic is not clear to me.

Last edited by Arun_Linux; 08-14-2012 at 05:03 AM.. Reason: removed while loop
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

3. Shell Programming and Scripting

Replace values in script reading line by line using sed

Hi all, Let's say I have a script calling for the two variables PA_VALUE and PB_VALUE. for pa in PA_VALUE blah blah do for pb in PB_VALUE blah blah do I have a text file with two columns of values for PA and PB. 14.5 16.7 7.8 9.5 5.6 3.6 etc etc I would like to read this... (7 Replies)
Discussion started by: crimsonengineer
7 Replies

4. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

5. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

6. Programming

C++ for loops in a single line

I am wondering whether I can write for loops in the following ways for (int i = 0; i < NL; i++) L->read_param(P, i + 1); for (int k = 0; k < lay; k++) sum += L->get_npar(); for (int i = 0; i < NL; i++) L = new Layer(Xi, Xf); for (int i = 0; i < NL; i++) { for (int j = 0; j < NL; j++)... (3 Replies)
Discussion started by: kristinu
3 Replies

7. Shell Programming and Scripting

Sed Comparing Parenthesized Values In Previous Line To Current Line

I am trying to delete lines in archived Apache httpd logs Each line has the pattern: <ip-address> - - <date-time> <document-request-URL> <http-response> <size-of-req'd-doc> <referring-document-URL> This pattern is shown in the example of 6 lines from the log in the code box below. These 6... (1 Reply)
Discussion started by: Proteomist
1 Replies

8. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

9. Shell Programming and Scripting

Preserving newlines when writing loops on the command line in bash

Dear All, I have a question that's been difficult to get an answer to. I often write command line loops, e.g. find files, print name, grep for term, apply sed, etc I use both zsh and bash. When I write a loop e.g. for line in `more myfile.txt` > do > echo $line > done but... (2 Replies)
Discussion started by: JohnK1
2 Replies

10. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies
Login or Register to Ask a Question