Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2009
    Posts
    56

    Question Unanswered: Get all files by search for a character "-" in all files from column 60 - 69

    Hello Friends,

    I need to get all file names where in if the file has "-" dash in the columns range from 60 - 69

    I mean to say if the file has "-" in the columns from 60 to 69 get that file name.

    i need either the command or ...may be script

    its a production issue and i need urgently..

    Tried but in vain..


    thanks

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool "-" dash in the columns range from 60 - 69?

    Try:
    Code:
    ls -1 /your/directory | awk 'substr($0,60,10) ~ "-" {print}'
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Nov 2009
    Posts
    56
    Thanks !!

    I need for look across all the directories right from current directory.

    Appreciate your help.

    thanks/

  4. #4
    Join Date
    Nov 2009
    Posts
    56
    The above command is not working though -

    $ls -1 | awk 'substr($0,60,10) ~ "-" {print}'

  5. #5
    Join Date
    May 2009
    Posts
    3
    This is in reply to http://www.dbforums.com/unix-shell-s...n-60-69-a.html .

    To list files that contain a dash in columns 60-69, you can use the following script.

    Code:
    var str list, file, content, line, columns60_69
    lf -rn "*" "/your/directory" > $list
    while ($list <> "")
    do
        lex "1" $list > $file ; cat $file > $content
        while ($content <> "")
        do
            lex "1" $content > $line ; wex "69]" $line > $columns60_69
            wex "[60" $columns60_69 > $columns60_69
            if ( { sen "^-^" $columns60_69 } > 0 )
                echo "FILE " $file ", LINE " $line
            endif
        done
    done

    This script is in biterscripting ( http://www.biterscripting.com ) . I chose it because this particular case, it was easier to write it in biterscripting.

    Wait.

    Are you looking for a dash in columns 60-69 in

    THE FILE NAME

    or in

    THE FILE CONTENTS

    ?


    If the dash has to be in columns 60-69 in file contents, I posted a solution at http://www.dbforums.com/chit-chat/16...-contents.html .
    Last edited by mike_bike_kite; 11-15-09 at 15:01. Reason: added this post to the original thread

  6. #6
    Join Date
    Nov 2009
    Posts
    56
    In the THE FILE CONTENTS please ....

    In the above script - can u explain me in steps .. i really don't have much knowledge .. appreciate your time

    thanks/MIKE

  7. #7
    Join Date
    May 2009
    Posts
    3
    @Mike

    In the above script - can u explain me in steps

    I added comments in the script. It is a good idea in any case. I also changed the script a bit.


    Code:
    # DECLARE VARIABLES.
    var str list, file, content, line, columns60_69
    
    # Get a list of all files in directory "/your/directory".
    lf -rn "*" "/your/directory" ($ftype=="f") > $list
    
    # $list has file names, one per line. Go thru the list.
    while ($list <> "")
    do
    
        # Get the next file name from the list. It is on the next line in $list.
        lex "1" $list > $file
    
        # The name of the file is in $file.
        echo -e "DEBUG: Processing file" " $file
    
        # Get the contents of the file into a string variable.
        cat $file > $content
    
        # The entire file contents are in $content. We will now use the same loop
        # as the above while loop. The above loop goes thru each file at a time.
        # In this loop, we will go thru each line in the file's contents at a time.
        # Same concept - process one line at a time.
        while ($content <> "")
        do
    
            # Get the next line from $content.
            lex "1" $content > $line
    
            # Extract characters 60-69 from this content line.
    
            # First, we will extract everything upto (]) 69th character.
            chex -p "69]" $line > $columns60_69
    
            # Next, we will extract everything starting with ([] 60th character.
            chex  "[60" $columns60_69 > $columns60_69
    
            # Now, columns 60-69 of this content line are in $columns60_69.
            # Does $columns60_69 contain a dash ?
            if ( { sen "^-^" $columns60_69 } > 0 )
    
                # Yes, there is a dash in $columns60_69. Write out
                # the name of the file, and the exact line.
                echo "FILE " $file ", LINE " $line
            endif
        done
    done

    To run this script, copy and paste this script in file "C:/Scripts/C6069.txt", the enter the following command in biterscripting.

    Code:
    script "C:/Scripts/C6069.txt"

    Change the "/your/directory" in the script to the correct path of the directory where these files are located.

  8. #8
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool Use ksh or bash

    I recommend you use a standard shell script like ksh or bash:
    Code:
    for filenm in /your/directory/*
    do
      awk 'substr($0,60,10) ~ /-/ {n+=1}
            END {print FILENAME" has "n" lines with dashes.";}' $filenm
    done
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •