move a file content to another directory

Thread Tools Search this Thread
# 1  
Question move a file content to another directory

my script is:

/u/user/orginal/:#! /bin/ksh
                      find . -name "aur_prog*" -exec grep -il "error" > test.out
                      #awk command to destination directory  
test.out file contain:

how to move this file(test.out) content to another directory using shell script
current directory: /u/user/orginal/test.out
destination directory:/u/user/filemv/

awk 'BEGIN {FS="/"} {print $2}' /u/user/filemv/

this awk will work??

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 07-18-2012 at 05:14 AM.. Reason: code tags
# 2  
This awk moves nothing. It just parses the input and shows the 2nd field where / is the field separator. Why don't you try it simply out?!

Most grep implementations have a -R switch so they can search recursive. If this is the case on your system, you don't need find:

grep -Ril "error" > test.out

You could also just pipe the output to your move:
grep -Ril "error"| xargs -I {} mv {} /some/other/directory

This User Gave Thanks to zaxxon For This Post:
# 3  
In case you really want test.out, then along with zaxxon's first solution, you could use the following to move files to a different directory:

while IFS='/' read x y; do mv $y /u/user/filemv/; done < test.out

This User Gave Thanks to balajesuri For This Post:
# 4  
/u/user/orginal/:this directory contain 100000+ files, so "grep" command won't work.
And /u/user/orginal/ this directory files are important,so i just can't move to another directory. In that condition im redirecting the output to test.out file and trying to move the content to destination directory(/u/user/filemv/)

hi guysSmilie
will u please help me out in this conditionSmilie

---------- Post updated at 03:54 PM ---------- Previous update was at 03:35 PM ----------

 while IFS='/' read x y; do mv $y /u/user/filemv/; done < test.out

code is working, but its moving the files from /u/user/orginal/ directory also.
i want to move the files only from test.out file to /u/user/filemv/, is there any way.

Last edited by roughwal; 07-20-2012 at 01:29 AM..
# 5  
Sorry but why does grep -R not work with searching 100.000+ files? You could change it from searching "*" to "aur_prog*" like in your find to narrow down the search but it shouldn't matter how many files to search.
# 6  
in the directory, "error" pattern is available in many kinda files. The need is, want "aur_proc" type of files error pattern the code contail "aur_prog*".

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move matching file to folder in same directory

The below bash executes but nothing is copied. I am trying to cp or mv the matching .pdf to the corresponding folder. There will always be a matching .pdf found but the number of folders may vary. The portion in red is what is used to match the .pdf--- variable $pdf to the folder--- variable... (11 Replies)
Discussion started by: cmccabe
11 Replies

2. Shell Programming and Scripting

Shell script cannot create directory and move the file to that directory

I have a script, which is checking if file exists and move it to another directory if then mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly ... (9 Replies)
Discussion started by: digioleg54
9 Replies

3. Shell Programming and Scripting

Move multiple files 4rm Source to different target folders based on a series num in the file content

Dear Experts my scenario is as follows... I have one source folder "Source" and 2 target folders "Target_123456" & "Target_789101". I have 2 series of files. 123456 series and 789101 series. Each series has got 3 types of fiels "Debit", "Refund", "Claims". All files are getting... (17 Replies)
Discussion started by: phani333
17 Replies

4. Shell Programming and Scripting

Move file in to directory- script

Hi In directory /mnt/upload I have about 100 000 files (*.png) that have been created during the last six months. Now I need to move them to right folders. eg: file created on 2014-10-10 move to directory /mnt/upload/20141010 file created on 2014-11-11 move to directory /mnt/upload/20141111... (6 Replies)
Discussion started by: primo102
6 Replies

5. UNIX for Dummies Questions & Answers

How to move file from one directory to other of only particular user?

I written unix script where a pdf file generates. But if the script is used by multiple people at a time it generates same pdf with two different owner names and creating a problem with permission while moving the file. is there a way where i can move the file filtering with the user? (4 Replies)
Discussion started by: lakers646
4 Replies

6. Shell Programming and Scripting

move content from one file to another

i have a file like: COURSE NAME: operating systems CREDITS:4 123456 66 234567 80 567892 64 COURSE NAME: C# CREDITS: 5 123456 67 345688 95 234567 78 COURSE NAME: Java CREDITS: 4 245562 88 123456 93 278962 95 COURSE NAME: Oracle CREDITS:5 278962 86 (5 Replies)
Discussion started by: poonam29
5 Replies

7. UNIX for Dummies Questions & Answers

Move content from directory to another

I have in root directory a folder A and a Folder B. I want to copy or move all content (many files) from A to B. How do I do that UNIX style? Thanks! (6 Replies)
Discussion started by: Matsakii
6 Replies

8. Shell Programming and Scripting

move contents from one file to another based on line number or content

I want a script that will move everything beyond a certain line number or beyond a certain content word into another file. For example, if file A has this: first line second line third line forth line fifth line sixth line I want to run a script that will move everything beyond the third... (4 Replies)
Discussion started by: robp2175
4 Replies

9. Shell Programming and Scripting

Move the latest or older File from one directory to another Directory

I Need help for one requirement, I want to move the latest/Older file in the folder to another file. File have the datetimestamp in postfix. Example: Source Directory : \a destination Directory : \a\b File1 : xy_MMDDYYYYHHMM.txt (xy_032120101456.txt) File2: xy_MMDDYYYYHHMM.txt... (1 Reply)
Discussion started by: pp_ayyanar
1 Replies

10. Shell Programming and Scripting

Move a file from windows directory to unix directory

Move a file from windows directory to unix directory, is this possible? if it is, can someone help me on this? Thanks! God bless! (1 Reply)
Discussion started by: kingpeejay
1 Replies

Featured Tech Videos