how to grep all the filenames in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to grep all the filenames in a script
# 1  
Old 02-10-2006
Java how to grep all the filenames in a script

hello,
we have a script (let say ABC) which contains the below:

lp -d lp06 -t 'REPORT FOR FINANCE -FIN-' $daily/FINRPT
lp -d lp06 -t 'REPORT FOR FINANCE -FIN1-' $daily/FINRPT1
lp -d lp06 -t 'REPORT FOR HUMAN RESOURCE -HR-' $dd_daily/HRRPT
lp -d lp06 -t 'REPORT FOR MANAGEMENT -MGM-' $dd_daily/MGMRPT
:
:
:

after executing ABC, we need to log down all the filename send for printing:
FINRPT
FINRPT1
HRRPT
MGMRPT
:
:
into a text file for further processing.

i've no idea how to grep all the filenames. Smilie
appreciate if anyone out there able to assist.

Thanks in advanced. Smilie
# 2  
Old 02-10-2006
Use Cut instead

cut -d'/' -f2 ABC > Log_Print_files

This will give you all files that were sent for printing in the file Log_Print_files.

Rahul.
# 3  
Old 02-10-2006
Another one here....

Quote:

awk -F"/" '{ print $2 }' ABC > ABC_Files
# 4  
Old 02-11-2006
Code:
sed 's/^.*\///g' filename

# 5  
Old 02-11-2006
Quote:
Originally Posted by matrixmadhan
Code:
sed 's/^.*\///g' filename

A better approach in sed would be to match from the end of the line, not from the start and select what is to be retained, not what is to be deleted, the solution proposed above will not work if any line containes more that one '/'. Where possible it is better to match to a positive pattern than a negative one.

something like the following which is untested:

Code:
sed -n 's%.*/\([^/][^/]*\)$%\1%p' filename

# 6  
Old 02-12-2006
Thanks guys! Smilie
really appreciate ur quick response.

i've another doubt here. Smilie

sometimes the script (let say ABC) print the SIMILAR report file twice but to DIFFERENT department.

For example, ABC contains

lp -d lp06 -t 'REPORT FOR FINANCE -FIN-' $daily/FINRPT
lp -d lp06 -t 'REPORT FOR MANAGEMENT -MGMFIN-' $daily/FINRPT

lp -d lp06 -t 'REPORT FOR FINANCE -FIN1-' $daily/FINRPT1
lp -d lp06 -t 'REPORT FOR HUMAN RESOURCE -HR-' $dd_daily/HRRPT
lp -d lp06 -t 'REPORT FOR MANAGEMENT -MGM-' $dd_daily/MGMRPT
:
:
:

So, when we grep out the report filename, the similar report filename would appear TWICE as below: Smilie
FINRPT
FINRPT

FINRPT1
HRRPT
MGMRPT

is there any possible way for us to get rid of the redundancy instead,
but getting the result (with FINRPT only appear ONCE):
FINRPT
FINRPT1
HRRPT
MGMRPT

Thanks in advanced. Smilie
# 7  
Old 02-12-2006
Just pipe the whole thing through sort -u

my_command_here | sort -u

Cheers
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing filenames in an array in shell script

hi, i am writing a shell script in which i read a line in a variable. FNAME="s1.txt s2.txt s3.txt s4.txt s5.txt" i want to create a array and store single file names in a array.. so the array should contain arr="s1.txt" arr="s2.txt" arr="s3.txt" arr="s4.txt" arr="s5.txt" how to... (3 Replies)
Discussion started by: Little
3 Replies

2. Shell Programming and Scripting

For/While Loop to Increment Filenames in a Script

Daily stupid question. I want to increment the file name everytime the script is run. So for example if the filename is manager.log and I run the script, I want the next sequence to be manager.log1. So to be clear I only want it to increment when the script is executed. So ./script... (10 Replies)
Discussion started by: metallica1973
10 Replies

3. Shell Programming and Scripting

Perl - grep issue in filenames with wildcards

Hi I have 2 directories t1 and t2 with some files in it. I have to see whether the files present in t1 is also there in t2 or not. Currently, both the directories contain the same files as shown below: $ABC.TXT def.txt Now, when I run the below script, it tells def.txt is found,... (5 Replies)
Discussion started by: guruprasadpr
5 Replies

4. UNIX for Dummies Questions & Answers

Help with grep - not showing filenames

Hello, I'm looking for a search string within about 50 files but when the string is found it doesn't tell me in which member it has been found. Any ideas how I can do this? Cheers Rob (4 Replies)
Discussion started by: Grueben
4 Replies

5. AIX

How to grep filenames from a file in other files?

Hi, We have a file called applcust.txt where we keep records of our customizations in the following format. We want to verify whether the file, which is in 3rd column in this file is there in another file called patch999999.log to find out if any of our customization has got overwritten by the... (2 Replies)
Discussion started by: sshah1001
2 Replies

6. Shell Programming and Scripting

Bash script - stripping away characters that can't be used in filenames

I want to create a temp file which is named based on a search string. The search string may contain spaces or characters that aren't supposed to be used in filenames so I want to strip those out. My thought was to use 'tr' with but the result is the opposite of what I want: $ echo "test... (5 Replies)
Discussion started by: mglenney
5 Replies

7. Shell Programming and Scripting

Whitespace in filenames in for loop in bash script

I'm trying to search all .odt files in a directory for a string in the text of the file. I've found a bash script that works, except that it can't handle whitespace in the filenames. #!/bin/bash if ; then echo "Usage: searchodt searchterm" exit 1 fi for file in $(ls *.odt); do ... (4 Replies)
Discussion started by: triplemaya
4 Replies

8. UNIX for Dummies Questions & Answers

how to grep filenames and sizes?

How to grep names and sizes of files in a directory by month and output to a file? ex: file1 | size1 file2 | size2 ... ... so on (2 Replies)
Discussion started by: helen008
2 Replies

9. Shell Programming and Scripting

perl script to list filenames that do not contain given string

Hi, I need to write a perl script that should do a search recursively in all the '*.txt' files for the string "ALL -Tcb" and should print only the file names that do not contain this string. (21 Replies)
Discussion started by: royalibrahim
21 Replies

10. Shell Programming and Scripting

Passing filenames/variables into a script

Hi! I'm somewhat new to Unix (I use it to fiddle, but not seriously), and at my work I have come to use it quite a bit. My question is this: I want to create a script to take the tedium out of repetitious tasks. However, I need to pass a file name into the script in order for it to work. ... (5 Replies)
Discussion started by: MrToast
5 Replies
Login or Register to Ask a Question