Sponsored Content
Full Discussion: For loop error
Top Forums UNIX for Beginners Questions & Answers For loop error Post 303043811 by ratheeshp123 on Friday 7th of February 2020 09:49:43 AM
Old 02-07-2020
sorry for not mentioning. I'm using bash.
also apologies for the errors in the code. without space and adding $ in the cat also not helping much.

Code:
cat /tmp/filename.txt | awk '{print $1}' | sort | uniq > /tmp/uniqlist.txt
for i in `cat /tmp/uniqlist.txt`
     do
         for j in "service1" "service16"
             do
                 for k in {1..6}
                     do
                         test_[$i]_[$j]_[$k]=$(cat /tmp/filename.txt | grep $i | grep $j | grep $k | wc -l)
                 done
        done
        echo -e $i, ${test_[$i]_[service1]_[1]}"-"${test_[$i]_[service1]_[2]}"-"${test_[$i]_[service1]_[3]}"-"${test_[$i]_[service1]_[4]}"-"${test_[$i]_[service1]_[5]}"-"${test_[$i]_[service1]_[6]}   ${test_[$i]_[service16]_[1]}"-"${test_[$i]_[service16]_[2]}"-"${test_[$i]_[service16]_[3]}"-"${test_[$i]_[service16]_[4]}"-"${test_[$i]_[service16]_[5]}"-"${test_[$i]_[service16]_[6]}     >> /tmp/output.txt
done
cat /tmp/output.txt

You seem to have missed the "expansion" of the variable in the echo statement?. Can you help me on this. I even tried printf but same result, or is there any other way I can get this output printed in a file.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by hicksd8; 02-07-2020 at 11:54 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Error in for loop?

Hi, Working on AIX using the following for loop. for a in `find /edi/iTracTEST/sessions -name nohup.out -print` do echo $a done On the command line it works fine, but insert the code in a file and then running it, it does not want to work. I get the following back. ' is not... (3 Replies)
Discussion started by: hugow
3 Replies

2. Shell Programming and Scripting

Error in Loop?

hi friends, i wrote one simple shell script.. in that am using for loop... when i am trying to execute the script.it shows syntax error at for loop line '((' unexpected. #!/bin/ksh ## ##### To find no of files in the directory NOF=`ls -l /root/COMM/LOGS/eds/20081025| wc -l`... (5 Replies)
Discussion started by: rdhaprakasam
5 Replies

3. UNIX for Dummies Questions & Answers

error in for loop???

Hi, I get the following output 98 -1 98 0 ./get_AB04-time: line 79: ((: i< && 0 !=7 : syntax error: operand expected (error token is "&& 0 !=7 ") I have this part of code. Line 79 is the line of the for loop. echo ${OCCURRENCE} $i_START CASE=0; i_END=${i_START}... (4 Replies)
Discussion started by: f_o_555
4 Replies

4. Shell Programming and Scripting

Error Using an if Loop Within a While Loop

Hello All, I am having a problem with an “if loop” within a “while loop” in my Korn Shell program. The basic concept of the program is that it searches for the existence of a series of load files in a load directory, and once it finds one of these files, it begins the following process: · Creates... (4 Replies)
Discussion started by: jonesdk5
4 Replies

5. Shell Programming and Scripting

Error with while loop

the program just prints all the command line arguments Getting error in the program error ./hellow: line 13: 0: command not found ./hellow: line 13: 0: command not found below is the program #!/bin/bash num=$# echo $num if then echo "No arguments are passed ." else ... (7 Replies)
Discussion started by: BHASKARREDDY006
7 Replies

6. Shell Programming and Scripting

Error in while loop

I have a file Table.out having table name like this Table_Emp Table_Exp Table_Fcr To show first 10 rows .. I' wrtng a script like this .. #!/bin/ksh cat /tmp/table.out|while read -r table vbar1 do <connect to db> then select * from $table limit 10; > /tmp/1.out done ... (3 Replies)
Discussion started by: netdbaind
3 Replies

7. Shell Programming and Scripting

Getting error in if loop

Hi All, while executing this code ,I'm gettign below Error if_test: line 3: #!/bin/bash if ; then echo "this is aginity;" elif ; then echo "this is informatica;" fi exit (3 Replies)
Discussion started by: netdbaind
3 Replies

8. Shell Programming and Scripting

Error in loop

This is my first ever bash script. What i wish to achieve is to find all files in current directory except the script file and count lines in each found file. Some thing seems to be wrong with the if statement :confused: Please help why it does not work? and maybe you have some ideas how to improve... (3 Replies)
Discussion started by: chinababy
3 Replies

9. Shell Programming and Scripting

Error in for loop

I was trying to implement a nested for do loop to run a perl script. for i in 1 10 50 do for j in 2 12 55 do perl script.pl "$i" "$i" "$j" done done when I implemented it within a shell script, i got the output, but every time j value will 55, or basically the last value of j in... (10 Replies)
Discussion started by: Kanja
10 Replies

10. UNIX for Beginners Questions & Answers

Error with for loop

There are two files abc_123.dat and abc_345.dat if at least one file exists then enter into the loop and remove file and exit. In first iteration, deleting files successfully but "else" statement executing after deleting files."else" should execute only if there is no file in the directory.... (1 Reply)
Discussion started by: Rajesh123
1 Replies
break(1)							   User Commands							  break(1)

NAME
break, continue - shell built-in functions to escape from or advance within a controlling while, for, foreach, or until loop SYNOPSIS
sh break [n] continue [n] csh break continue ksh *break [n] *continue [n] ksh93 +break [n] +continue [n] DESCRIPTION
sh The break utility exits from the enclosing for or while loop, if any. If n is specified, break n levels. The continue utility resumes the next iteration of the enclosing for or while loop. If n is specified, resume at the n-th enclosing loop. csh The break utility resumes execution after the end of the nearest enclosing foreach or while loop. The remaining commands on the current line are executed. This allows multilevel breaks to be written as a list of break commands, all on one line. The continue utility continues execution of the next iteration of the nearest enclosing while or foreach loop. ksh The break utility exits from the enclosed for, while, until, or select loop, if any. If n is specified, then break n levels. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be exited. The continue utility resumes the next iteration of the enclosed for, while, until, or select loop. If n is specified then resume at the n- th enclosed loop. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be used. On this manual page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words that follow a command preceded by ** that are in the format of a variable assignment are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign, and also that word splitting and file name generation are not performed. ksh93 break is a shell special built-in that exits the smallest enclosing for, select, while, or until loop. It also exits the nth enclosing loop if n is specified. Execution continues at the command following the loop or loops. If n is specified, it must be a positive integer >=1. If n is larger than the number of enclosing loops, the last enclosing loop is exited. continue is a shell special built-in that continues execution at the top of the smallest enclosing for, select, while, or until loop, if any; or of the top of the nth enclosing loop if n is specified. If n is specified, it must be a positive integer >=1. If n is larger than the number of enclosing loops, the last enclosing loop is used. On this manual page, ksh93(1) commands that are preceded by one or two + symbols are special built-in commands and are treated the follow- ing ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Built-in commands are not valid function names. 5. Words following a command preceded by ++ that are in the format of a variable assignment are expanded with rules as a variable assignment. This means that tilde substitution is performed after the = sign and field splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), exit(1), ksh(1), ksh93(1), sh(1), attributes(5) SunOS 5.11 8 Apr 2008 break(1)
All times are GMT -4. The time now is 06:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy