Run command on each and every logs of dir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run command on each and every logs of dir
# 1  
Old 04-09-2012
Bug Run command on each and every logs of dir

HI

i have below command and i want to run it on each logs of each and every Dir.

Code:
/home/Laco/Al

I have sub dir in this folder

/home/Laco/Al/04092012/LP/X/*.logs
/home/Laco/Al/04092012/LP/Y/*.logs
/home/Laco/Al/04092012/LP/Z/*.logs
/home/Laco/Al/04092012/LP/P/*.logs

I want to run command
Code:
tr -c '[:print:][:cntrl:]' '[-*]' | sed 's/---/-/g'

and save output at same file.

Basically it replace ASCI Value

Thanks
# 2  
Old 04-09-2012
Code:
for file in `find . -type f -name \*.logs`;do
   cat $file | tr -c '[:print:][:cntrl:]' '[-*]' | sed 's/---/-/g' > $file"_tmp"
   mv $file"_tmp" $file
done

This User Gave Thanks to 47shailesh For This Post:
# 3  
Old 04-09-2012
Correction and rearrangement of 47shailesh post.

No attempt to test the tr command syntax because it is some weird Linux (i.e. non-unix) extension.

Code:
find . -xdev -type f -name \*.logs | while read filename
do
    cat "${filename}" | tr -c '[:print:][:cntrl:]' '[-*]' | sed 's/---/-/g' > "${filename}_tmp"
   mv "$filename_tmp" "${filename}"
done

This User Gave Thanks to methyl For This Post:
# 4  
Old 04-09-2012
Bug

Not solved ....can you please help me with perfect script.....

error mv: cannot access

Thanks

Last edited by asavaliya; 04-09-2012 at 09:31 PM..
# 5  
Old 04-10-2012
Combining input from the other thread, try this. First test it out on a test directory structure..
Code:
for file in */LP/*/*.logs
do 
  LANG=C sed 's/[^[:print:][:cntrl:]]\{1,\}/-/g' "$file" > "$file.new" && mv -- "$file.new" "$file"
done

This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 04-10-2012
Bug

Thanks a lot it's working....

Thanks a lot all of you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies

2. Shell Programming and Scripting

Using DIR command in FTP

Hi, Can the below command will be working in FTP dir */*/*/*.zip I want to dynamically know the folder names where the zipfiles are present. Thnx in advance. (1 Reply)
Discussion started by: weknowd
1 Replies

3. Shell Programming and Scripting

can I run a exe which is at bin dir from my script.

Hello forum memebers. I have command which is exe of C- program from my script.i am writing a script which is under path /abc/xyz/test.sh. the script consist the command which is the exe of c-prog and the exe is present in the /abc/xyz/bin.if run the command from the /abc/xyz its running and if... (3 Replies)
Discussion started by: rajkumar_g
3 Replies

4. Shell Programming and Scripting

Script to run a command on all txt files present in a dir structure

Hi, I have a directory structure like the one given below root\a\b1 root\a\b2 root\b\b1 root\b\b2 . . . root\j\b1 root\j\b2 Now, there are a txt files in each dir and subdir, there is a root.txt I have to write a script where in i have to run a command called "genrb <filename>"... (6 Replies)
Discussion started by: vikramsinghnegi
6 Replies

5. UNIX for Dummies Questions & Answers

Cron job to run a command from another dir?

I would like to setup a cron job to run a command from another directory. What is the best way to do this? The cron file is in a directory and the script I want it to run is in another directory. I tried doing this in the cron file: /location/of/command/run.sh But that did not work.... (2 Replies)
Discussion started by: Sepia
2 Replies

6. UNIX for Dummies Questions & Answers

command logs

Is there a place were the system stores logs of command's? like does it log whatever changes I made? I'm using a Centos 5.x box Thank you (2 Replies)
Discussion started by: mcraul
2 Replies

7. UNIX for Dummies Questions & Answers

How to get dir name tacked onto filename with ls command

hello i'm trying to figure out how to tack the directory name onto the file name when i do the ls -ltrR command please? --------------------------------------------------------------------------------- I do the following command ls -ltrR > ls.out and get the following output:... (5 Replies)
Discussion started by: bobk544
5 Replies

8. Shell Programming and Scripting

Perl command syntax for C:\dir

Hi Everyone, Perl command syntax that would display my ... C:\dir .... Regards, asabzevari (1 Reply)
Discussion started by: asabzevari
1 Replies

9. Shell Programming and Scripting

script to go to a different dir to run a commandline prompt in that dir

Hi, I need to know how I'll be able to write a script that can goto a different dir where I don't have access to read,write and execute and also to run a commandline prompt in that dir with one file whose path has to be specified in that command. Will I be able to do this? Any ideas or... (2 Replies)
Discussion started by: ann_124
2 Replies

10. UNIX for Advanced & Expert Users

Using the ps command from ucb dir

On a Sun OS system we have, when executing a ps command it displays a third parties applications password. The ps command used is from the ucb dir, but if you use the ps command which resides in the bin dir it doesn't display the password. Other users need to use the ps command from the ucb... (2 Replies)
Discussion started by: dbrundrett
2 Replies
Login or Register to Ask a Question