Redirect grep output to dynamique fileName and subdirectory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirect grep output to dynamique fileName and subdirectory
# 8  
Old 10-24-2008
you need to test of the directory exists - not then create it.
Code:
[[ -d ./tmp/$all/error ]] || mkdir ./tmp/$all/error

And don't use the \ characters in directory path names that's a windows thing - it will cause the shell to do the wrong thing
# 9  
Old 10-24-2008
ive make
Code:
for all in `find  ./clafzecxs2.edfgdf.fr -type f -name "*20081014.log"`
do 
 file = `basename $all`
 print $file
done

i get someting like :

Quote:
=: cannot open: No such file or directory
workshop_debug-PBP_20081014.log:
that resolve the file name but how i can use it on my loop

other question `dirname $all` dont get the directory path
any suggestion

thanks
# 10  
Old 10-24-2008
try echo instead of print and also there is not space between file = `ba...

it is also probably not best to use the variable "file" since it is a system command...

Code:
 
for all in `find  ./clafzecxs2.edfgdf.fr -type f -name "*20081014.log"`
do 
file=`basename $all`
echo $file
done

# 11  
Old 10-24-2008
Hi jim

if you see the loop suggested by 'sethcoop' and that get a part for my need
Code:
for all in `find ./ -type f -name "*.log"`
do 
  grep error $all > ./tmp/$all.error
done

the $all is the full path and file name, so
Code:
[[ -d ./tmp/$all/error ]] || mkdir ./tmp/$all/error

will get an error

i need a way to substitute the path an the file name
in each iteration, and use your suggestion properly ( [[ -d ./tmp/$all/error ]] || mkdir ./tmp/$all/error )

thank you 'sethcoop' and 'jim'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirect script output to file after grep

i have simple program that generate log file 1 line every sec, i need to do grep for specific record then redirect to another file. #!/bin/bash for i in `seq 1 20`; do echo $i sleep 1 done ./test.sh |egrep "5|10|15" 5 10 15 r ./test.sh... (2 Replies)
Discussion started by: before4
2 Replies

2. Shell Programming and Scripting

Find: filename in every subdirectory matching a pattern

Hi, I have multiple directories built in following manner /app/red/tmp /app/blue/upd /app/blue/tmp /app/green/tmp /app/red/upd /app/green/upd I have filenames having pattern ONE.XXX.dat TWO.ZZZ.dat and so on across the folders listed above My objective is to list all filenames of a... (4 Replies)
Discussion started by: wahi80
4 Replies

3. UNIX and Linux Applications

How to redirect grep command output to same file

Hi Everyone, Can anyone please tell me, how can I redirect the grep command output to same file. I am trying with below command but my original file contains no data after executing the command. $grep pattern file1 > file1 Kind Regards, Eswar (5 Replies)
Discussion started by: picheswa
5 Replies

4. Shell Programming and Scripting

find and replace in subdirectory (filename & content - both)

Hi, I have to rename all occurance of CUST_MST to RESELLER_MST both in filename and file content under a directory (say D0) which contains multiple (2-3 levels) sub directory. Example: D0 -> D1 -> D2 has a file CUST_MST_TEMP.txt this contains : > cat /D0/D1/D2/CUST_MST_TEMP.txt... (3 Replies)
Discussion started by: sabyasm
3 Replies

5. Shell Programming and Scripting

how to redirect the output of a grep command to a file inside a shell script

hi, i wat to get the output of a grep command in a file. but when i am trying out the same grep command in the unix prompt its working fine.. i am getting the output properly.. but when i am writing the same command inside my shell script , its just creating a new output file with no contents... (11 Replies)
Discussion started by: kripssmart
11 Replies

6. Shell Programming and Scripting

Redirect grep output into file !!!!!

Hi, I am writing the following code in command prompt it is working fine. grep ',222,' SAPPCO_20080306.CSV_old > SAPPCO_20080306.CSV_new But the command is not working in the Shell Script... ########################################## #!/bin/sh #... (2 Replies)
Discussion started by: hanu_oracle
2 Replies

7. Shell Programming and Scripting

redirect the grep output into the variable

i want to redirect the grep output into the variable but i am not able to get it i tried veri=`grep -i $1 "${logdir}"* | grep -i adding | grep -iv equation | tail -1 | cut -d ':' -f 1` vari=$(grep -i $1 "${logdir}"* | grep -i adding | grep -iv equation | tail -1 | cut -d ':' -f 1) BUT NOT... (1 Reply)
Discussion started by: mail2sant
1 Replies

8. UNIX for Dummies Questions & Answers

How to grep / zgrep to output ONLY the matching filename and line number?

Hi all, I am trying to zgrep / grep list of files so that it displays only the matching filename:line number and does not display the whole line, like: (echo "1.txt";echo "2.txt") | xargs zgrep -no STRING If I use -o option, it displays the matching STRING and if not used, displays the... (3 Replies)
Discussion started by: vvaidyan
3 Replies

9. Shell Programming and Scripting

grep string and output filename

Hello, I have over 200 files and some of them have the string like "John price $200". I would like to grep the string. Then output the filename which found the string. I have the following script, but it ONLY output the string echo Please input list file name: read listn for file in `cat... (3 Replies)
Discussion started by: happyv
3 Replies

10. Shell Programming and Scripting

Losing filename in grep output

I have the following line in a script that searches files in several directories and shows the search results on the screen. ls "$path" | xargs cat | tr -s " " | fgrep -i "$search_arg" But, because I'm also using CAT and TR, the output from the search does not display the name of the file... (6 Replies)
Discussion started by: netguy
6 Replies
Login or Register to Ask a Question