Sponsored Content
Top Forums Shell Programming and Scripting Deleting table cells in a script Post 302265171 by phpfreak on Friday 5th of December 2008 08:04:39 PM
Old 12-05-2008
k, I have a few issues/questions at this point. When I run my script it errs:

Code:
[: !=: unexpected operator
[: !=: unexpected operator


Seems that part of ddreggors code is breaking during the test command. I'm going to man test to see if I can dig up something there, here, or elsewhere.

Secondly, and please bare with me on this as I'm still learning, but what can I do to tell the script to 'do nothing and keep going' vs. echo "blah" in my loop. I feel like I'm just filling in the blanks here because I'm stumped since I'm sure if I leave it out, it'll break. Would the solution be to just echo to devnull? Smilie

Third, ddreggors, I'm looking around right now but if I'm going to use your sed example, I'll need an expression a little more complex than yours since the range of characters goes beyond just [x-z] I think what I need is [a-zA-Z0-9]. Also needs to include "(|)|:|.|,|/" (brackets, semicolons, periods, commas, slashes if I noted that right). I'll try with my own sed example first then explore later if need be.


Code:
#!/bin/sh

#TD=0
CT=0
cat status.html |while read LINE
do
    # Check to see if the LINE is non-empty, and has a <td> tag in it.
    if [ -n "$LINE" -a `echo $LINE |grep "<td>"` != "" ] ; then
        # Increase the TD counter by 1
        CT=`echo "$CT+1" |bc`
        
        # Check to see if the TD counter is at 6 (we are at 7th TD as the counter starts at 0 not 1)
        if [ "$CT" -eq 6 ] ; then
            # Use sed to remove this TD tag AND everything in between
            echo $LINE |sed -n '/<tr>/,/<\/tr> {
                                            s/.*<tr>//
                                            s/<\/tr>.*//
                                            p
                                            }' >> ztmp.Ps23zp2s.2-Fpps3-wmmm0dss3
        else 
            echo $LINE >> ztmp.Ps23zp2s.2-Fpps3-wmmm0dss3
        fi
    else
        echo $LINE >> ztmp.Ps23zp2s.2-Fpps3-wmmm0dss3
    fi
    
    # If we are leaving a table row the we need to reset the TD counter!
    if [ -n "$LINE" -a `echo $LINE |grep "</tr>"` != "" ] ; then
                CT=0
    else
    	echo "No reset"
	fi
	
    if [ -n "$LINE" -a `echo $LINE |grep "</html>"` != "" ] ; then 
                mv ztmp.Ps23zp2s.2-Fpps3-wmmm0dss3 status.html
		else	
			echo "Not done yet, keep going" 
		fi

done

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

rm -i and deleting files from an index table

Hi, I am trying to make a command to delete my files out the trash can, but one at a time. I am currently using rm - i to do this, but the original file locations for restoring my files are heard on a .txt file which I am using as an index table. How would I manage to make it so that if I... (21 Replies)
Discussion started by: E-WAN
21 Replies

2. UNIX for Dummies Questions & Answers

Deleting cells that contain a specific number only from a space delimited text file

I have this space delimited large text file with more than 1,000,000+ columns and about 100 rows. I want to delete all the cells that consist of just 2 (leave 2's that are not by themselves intact): File before modification aa bb cc 2 NA100 dd aa b1 c2 2 NA102 de File after modification... (1 Reply)
Discussion started by: evelibertine
1 Replies

3. UNIX for Dummies Questions & Answers

Filling empty cells

How do you fill empty cells that do not have any data in them with "X" in a tab delimited text file? Thanks! (4 Replies)
Discussion started by: evelibertine
4 Replies

4. Shell Programming and Scripting

Moving new row and deleting old row to another table

Hi, I want to move a new row to another table if the field from new row doesn't have the first word that I categorized (like: IRC blablabla, PTM blablabla, ADM blablabla, BS blablabla). I already use this script but doesn't work as I expected. CHECK_KEYWORD="$( mysql -uroot -p123456 smsd -N... (7 Replies)
Discussion started by: jazzyzha
7 Replies

5. Shell Programming and Scripting

In php, Moving a new row to another table and deleting old row

Hi, I already succeed moving a new row to another table if the field from new row doesn't have the first word that I categorized (like: IRC blablabla, PTM blablabla, ADM blablabla, BS blablabla). But it can't delete the old row. Please help me with the script. my php script: INSERT INTO... (2 Replies)
Discussion started by: jazzyzha
2 Replies

6. UNIX for Dummies Questions & Answers

Deleting unwanted text from a table

Hi everyone, I have a microbial diversity table in the format ;k__kingdom; p__phylum, etc, somer rows have descriptions before the :k__ (like the af028349.1 below) is there a way I can get rid of this text (which is different every time) and keep all the other columns? Thanks a bunch! ;... (1 Reply)
Discussion started by: Juan Gonzalez
1 Replies

7. Programming

Perl script to merge cells in column1 which has same strings, for all sheets in a excel workbook

Perl script to merge cells ---------- Post updated at 12:59 AM ---------- Previous update was at 12:54 AM ---------- I am using below code to read files from a dir and print to excel. open(my $in, '<', $file) or die "Could not open file: $!"; my $rowCount = 0; my $colCount = 0;... (11 Replies)
Discussion started by: Jack_Bruce
11 Replies

8. UNIX for Beginners Questions & Answers

BASH SCRIPT - Insert date into cells in cvs file

Hi, I'm looking to accomplish the following. Insert current date into three places/cells within a cvs, every time the bash script is executed. The cells are column A,B,C row 2. Row 1 is reserved for the headers. The file name is always orders.csv. These three cells we always have an old... (1 Reply)
Discussion started by: Rookievmc
1 Replies

9. UNIX for Beginners Questions & Answers

Merge cells in all rows of a HTML table dynamically.

Hello All, I have visited many pages in Unix.com and could find out one solution for merging the HTML cells in the 1st row. (Unable to post the complete URL as I should not as per website rules). But, however I try, I couldn't achieve this merging to happen for all other rows of HTML... (17 Replies)
Discussion started by: Mounika
17 Replies

10. UNIX for Beginners Questions & Answers

Remove duplicates in a dataframe (table) keeping all the different cells of just one of the columns

Hello all, I need to filter a dataframe composed of several columns of data to remove the duplicates according to one of the columns. I did it with pandas. In the main time, I need that the last column that contains all different data ( not redundant) is conserved in the output like this: A ... (5 Replies)
Discussion started by: pedro88
5 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 06:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy