Finding tags in file names using csh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding tags in file names using csh
# 1  
Old 11-02-2010
Finding tags in file names using csh

I have the following script and want to check if in each $f there exists either a "drw" or "smp" tag in the file name. How can I do it?

For example

npt06-32x24drw has the "drw" tag
npt06-32x24smp has the "smp" tag
npt06-32x24 no "drw" or "smp" tag found

Code:
#!/bin/csh

  set iarg = 0
  set optusage = 0
  set opteg = 0
  set opthelp = 0
  set optinfo = 0
  set fnames = ""

  alias MATH 'set \!:1 = `echo "\!:3-$" | bc -l`'
  set narg = $#argv
  while ($iarg < $narg)

    MATH iarg = $iarg + 1
    set arg = $argv[$iarg]
    set opt = ` echo $arg | awk 'BEGIN { FS="=" } { print $1 }'  \
                          | tr "[a-z]" "[A-Z]" `
    set par = ` echo $arg | awk 'BEGIN { FS="=" } { print $2 }' `

    switch ($opt)
    case "-USAGE":
        set optusage = 1
        set optinfo = 1
        breaksw
    case "-EG":
        set opteg = 1
        set optinfo = 1
        breaksw
    case "-HELP":
        set opthelp = 1
        set optinfo = 1
        breaksw
    default:
        set flog = `echo $arg | awk 'BEGIN {FS=".log"} {print $1}'`
        set fnames = "$fnames $flog"
    endsw

  end   # while



  if ($fdrw) then

    foreach f ($fnames)

      echo "(I) ${f}.log, (O) ${f}.mis"

      grep "Rms Value" $f*.log              \
        | awk '{ if ($0 !~ /run[0-9]+\.log:0\. /)  \
                 { sub(/[^:]*:[0-9]*\.[ \t]*/,x); print i++". " $0 }  \
               }' > $f.mis

      grep "Best Value" $f*.log             \
        | awk '{ if ($0 !~ /run[0-9]+\.log:0\. /)  \
                 { sub(/[^:]*:[0-9]*\.[ \t]*/,x); print i++". " $0 }  \
               }' >> $f.mis

    end

  elseif ($fsmp) then

    foreach f ($fnames)

      echo "(I) ${f}.log, (O) ${f}.mis"

      grep "Best Value" $f*.log             \
        | awk '{ if ($0 !~ /run[0-9]+\.log:0\. /)  \
                 { sub(/[^:]*:[0-9]*\.[ \t]*/,x); print i++". " $0 }  \
               }' >> $f.mis

  endif


  echo ""
  echo "END"
  echo ""

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding a string in a list of files, print file names

I'm interested in writing a report script using BASH that searches all of the files in a particular directory for a keyword and printing a list of files containing this string... In fact this reporting script would have searches for multiple keywords, so I'm interested in making multiple... (2 Replies)
Discussion started by: chemscripter904
2 Replies

2. Shell Programming and Scripting

Finding size of files with spaces in their file names

I am running a UNIX script to get unused files and their sizes from the server. The issue is arising due to the spaces present in the filename/folder names.Due to this the du -k command doesn't work properly.But I need to calculate the size of all files including the ones which have spaces in them.... (4 Replies)
Discussion started by: INNSAV1
4 Replies

3. Shell Programming and Scripting

Finding File Names Ending In 3 Random Numerical Characters

Hi, I have a series of files (upwards of 500) the filename format is as follows CC10-1234P1999.WGS84.p190 each of this files is in a directory named for the file but excluding the extension. Now the last three numeric characters, in this case 999, can be anything from 001 to 999, I need to... (3 Replies)
Discussion started by: roche.j.mike
3 Replies

4. Shell Programming and Scripting

Finding consecutive numbers in version names on a txt file

Hi all. I have a directory which contains files that can be versioned. All the files are named according to a pattern like this: TEXTSTRING1-001.EXTENSION TEXTSTRING2-001.EXTENSION TEXTSTRING3-001.EXTENSION ... TEXTSTRINGn-001.EXTENSION If a file is versioned, a file called ... (10 Replies)
Discussion started by: fox1212
10 Replies

5. UNIX for Dummies Questions & Answers

Finding names in multiple files - second attempt

I couldn't find the original thread that I created and since I didn't get a definitive answer, I figured I'd try again. Maybe this time I can describe what I want a little better. I've got two files, each with thousands of names all separated by new line. I want to know if 'name in file1'... (2 Replies)
Discussion started by: Rally_Point
2 Replies

6. UNIX for Dummies Questions & Answers

Finding Names in multiple files

What's the best way to see if a common name exists in two separate files? (3 Replies)
Discussion started by: Rally_Point
3 Replies

7. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

8. Shell Programming and Scripting

Finding missing sequential file names

So, I've got a ton of files that I want to go through (ie something like 300,000), and they're all labeled sequentially. However I'm not 100% positive that they are all there. Is there any way of running through a sequence of numbers, checking if the file is in the folder, if not appending it... (2 Replies)
Discussion started by: Julolidine
2 Replies

9. Shell Programming and Scripting

CSH - finding files with the same file extension

Hey, I'm having a problem finding out if a directory holds any files with a certain file extension, for example .txt. I have tried: if (! -e "*.txt") and I've tried: set FILES=`ls *` echo "Found $FILES" foreach FILE ($FILES) if($FILE == "*.txt") And neither of... (2 Replies)
Discussion started by: amnesiaiom
2 Replies

10. Shell Programming and Scripting

how to find capital letter names in a file without finding words at start of sentence

Hi, I want to be able to list all the names in a file which begin with a capital letter, but I don't want it to list words that begin a new sentence. Is there any way round this? Thanks for your help. (1 Reply)
Discussion started by: kev269
1 Replies
Login or Register to Ask a Question