If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Get all files by search for a character "-" in all files from column 60 - 69

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-13-09, 07:16
MIKELALA MIKELALA is offline
Registered User
 
Join Date: Nov 2009
Posts: 45
Question 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
Reply With Quote
  #2 (permalink)  
Old 11-13-09, 12:25
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
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
Reply With Quote
  #3 (permalink)  
Old 11-14-09, 13:09
MIKELALA MIKELALA is offline
Registered User
 
Join Date: Nov 2009
Posts: 45
Thanks !!

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

Appreciate your help.

thanks/
Reply With Quote
  #4 (permalink)  
Old 11-14-09, 13:20
MIKELALA MIKELALA is offline
Registered User
 
Join Date: Nov 2009
Posts: 45
The above command is not working though -

$ls -1 | awk 'substr($0,60,10) ~ "-" {print}'
Reply With Quote
  #5 (permalink)  
Old 11-15-09, 12:40
RandiR RandiR is offline
Registered User
 
Join Date: May 2009
Posts: 3
This is in reply to Get all files by search for a character "-" in all files from column 60 - 69 .

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 14:01. Reason: added this post to the original thread
Reply With Quote
  #6 (permalink)  
Old 11-22-09, 07:31
MIKELALA MIKELALA is offline
Registered User
 
Join Date: Nov 2009
Posts: 45
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
Reply With Quote
  #7 (permalink)  
Old 11-29-09, 15:51
RandiR RandiR is offline
Registered User
 
Join Date: May 2009
Posts: 3
@Mike

Quote:
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.
Reply With Quote
  #8 (permalink)  
Old 11-30-09, 09:24
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On