Sponsored Content
Full Discussion: Logical if error
Top Forums Shell Programming and Scripting Logical if error Post 302829335 by nss280 on Thursday 4th of July 2013 03:27:36 PM
Old 07-04-2013
Hi Alister,

Thank you for the quick reply. I tried as you suggested but still its showing me the same error

Code:
$ vi prog11.sh
"prog11.sh" 22 lines, 646 characters
echo "Enter file name"
read FILENAME=$1
linecount=0
charcount=0
n=0
linecount=`wc -l $FILENAME | cut -d " " -f7`
if [ $linecount -ge 0 ]; then
        while [ $nu -ne $linecount ]
                do
                nu=`expr $nu + 1`
                line=`sed -n ''$nu'p' $FILENAME`
                charcount=`echo $line | wc -c`
if [ "$countchar" > "20" ] && [ "$countchar" < "25" ];
then
                                        echo "Line with length between 20 and 25"
                                        echo $charcount $line
                        fi
                done
else
        echo "Error: no lines in the file"
        exit 1
fi
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"prog11.sh" 22 lines, 647 characters
$ sh prog11.sh
Enter file name
myfile
[: 14: unexpected operator
$

---------- Post updated at 12:57 AM ---------- Previous update was at 12:51 AM ----------

I am in bash.

Even tried without quotes, still not working Smilie

Code:
$ vi prog11.sh
"prog11.sh" 23 lines, 647 characters
echo "Enter file name"
read FILENAME=$1
linecount=0
charcount=0
n=0
linecount=`wc -l $FILENAME | cut -d " " -f7`
if [ $linecount -ge 0 ]; then
        while [ $nu -ne $linecount ]
                do
                nu=`expr $nu + 1`
                line=`sed -n ''$nu'p' $FILENAME`
                charcount=`echo $line | wc -c`
if [ $countchar > 20 ] && [ $countchar < 25 ]
then
                                        echo "Line with length between 20 and 25"
                                        echo $charcount $line
                        fi
                done
else
        echo "Error: no lines in the file"
        exit 1
fi

~
~
~
~
~
~
~
~
~
~
~
~
~
"prog11.sh" 23 lines, 639 characters
$ sh prog11.sh
Enter file name
myfile
[: 14: unexpected operator
$


Regards,
Nss280
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Error in creating logical partition

Dear Members, I am using SCO-Unix 5.0.5. I have created 2 logical drives but some of the blocks are overlapped and are now giving warning during startup. I have used fsck to settle the problems but to no avail. Kindly help me to sort out the problem. Thanks (3 Replies)
Discussion started by: nagendrajaiswal
3 Replies

2. Shell Programming and Scripting

logical if condition

hi i have the following scenario #!/bin/sh a=21.0 b=33.0 c=16.0 cmd=20 cmd1=30 if && ] then echo "problem....." exit 1 else echo "ok" exit 0 fi the issue here is the above condition is never TRUE coz a>cmd && b >cmd1 (7 Replies)
Discussion started by: nano2
7 Replies

3. Shell Programming and Scripting

logical OR in sed

frnds.. can i perform an OR operation in sed syntax ? if yes.. how? I need to search for some 2-3 mail addresses in multiple files and delete all those... and instead of them.. I need to insert a new mail id...( these are also other emails in that list .. which sud not be affected ) is... (8 Replies)
Discussion started by: clx
8 Replies

4. Shell Programming and Scripting

How to do logical AND and logical OR with grep

Hi can someone please help me on this. I need to perform this code: Grep any lines that meets the following criteria (A AND B) OR (A AND C) I tried this code, but it didn't work Grep-I "A &&B" | "A&&C" *.* $ thanks in advance (12 Replies)
Discussion started by: Needhelp2
12 Replies

5. Shell Programming and Scripting

logical expressions

Hi Fdz, I have to verify the length of two uids are equals to 11 or not. The conditions is both lengths should be 11.I tried with this logic expr. am unable to get correct results.(Shell script in Unix i need) if do echo"Results" done Thanx (2 Replies)
Discussion started by: KiranKumarKarre
2 Replies

6. UNIX for Dummies Questions & Answers

problem using logical or

Hi, I have a script testor.s which takes a string as command line argument, Contents of the script: #!/bin/ksh -x if ] then echo "error" else echo "correct" fi Here, though i provide the command line argument as "WO_STMT_05292009", it displays error Is there... (3 Replies)
Discussion started by: Sheema
3 Replies

7. Shell Programming and Scripting

Logical error

I have this script to uvscan-update. Seems like that i am getting logical error at the end of the script. It is updating the script and also giving the error message to update it manually. I have deleted the DAT files to see if it will create new and it does. Below is the error and the script: ... (1 Reply)
Discussion started by: mk07md
1 Replies

8. Programming

Logical Error With Type Conversion In C

So, I'm into about 650 lines of some code I'm working on. So I'll try to explain instead of flooding this post. Say I have some code like this: int main() { int i, j; char data; printf("Gimme something: "); fgets(data, INPUT_BUFF, stdin); for (j = 0; j < data; j++){... (6 Replies)
Discussion started by: Azrael
6 Replies
MSSQL_FIELD_SEEK(3)													       MSSQL_FIELD_SEEK(3)

mssql_field_seek - Seeks to the specified field offset

SYNOPSIS
bool mssql_field_seek (resource $result, int $field_offset) DESCRIPTION
Seeks to the specified field offset. If the next call to mssql_fetch_field(3) won't include a field offset, this field would be returned. PARAMETERS
o $result - The result resource that is being evaluated. This result comes from a call to mssql_query(3). o $field_offset - The field offset, starts at 0. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Using mssql_field_seek(3) on the example for mssql_fetch_field(3) <?php // Connect to MSSQL and select the database mssql_connect('MANGOSQLEXPRESS', 'sa', 'phpfi'); mssql_select_db('php'); // Send a select query to MSSQL $query = mssql_query('SELECT * FROM [php].[dbo].[persons]'); // Construct table echo '<h3>Table structure for 'persons'</h3>'; echo '<table border="1">'; // Table header echo '<thead>'; echo '<tr>'; echo '<td>Field name</td>'; echo '<td>Data type</td>'; echo '<td>Max length</td>'; echo '</tr>'; echo '</thead>'; // Dump all fields echo '<tbody>'; for ($i = 0; $i < mssql_num_fields($query); ++$i) { // Fetch the field information, notice the // field_offset parameter is not set. See // the mssql_field_seek call below $field = mssql_fetch_field($query); // Print the row echo '<tr>'; echo '<td>' . $field->name . '</td>'; echo '<td>' . strtoupper($field->type) . '</td>'; echo '<td>' . $field->max_length . '</td>'; echo '</tr>'; // Move the internal seek pointer to the next // row in the result set mssql_field_seek($query, $i + 1); } echo '</tbody>'; echo '</table>'; // Free the query result mssql_free_result($query); ?> SEE ALSO
mssql_fetch_field(3). PHP Documentation Group MSSQL_FIELD_SEEK(3)
All times are GMT -4. The time now is 10:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy