INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

move search contents to a text.file

move search contents to a text.file

(OP)
Dear all,

I am using Oracle Solaris.

I would like to accomplish the following.

1. I would like to search files names and move the search contents of the all files returned in the search to another text file. All the files should be clubbed one after another in a single file.

Example.

grep filename.* (this will give me all files. I want to combine the all files to a single text file). How can I accomplish this ?

2. I would like to now search inside the files and move all the files matching the search to a specific directory.

Example.
grep "PO#" filename.* (this will search all filenames with the specific PO value and the result should be moved to ../mydir/

Thank you for your help.

JF

RE: move search contents to a text.file

1) direct the command output to a file

append

CODE --> shell

> filename 
to send the output from the command line to a new file.

or

CODE --> shell

>> filename 
to append the output to an existing file.


2)
http://www.howtogeek.com/168164/move-files-into-on...

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: move search contents to a text.file

(OP)
Hi Chris,

thank you for your response. But for the first one, I tried and it only moves the search results into the output file. I am looking to copy the the file contents of the search result into single file.

for example.

if my search result returns two files : file 1 and file 2.
file 1 contains
ABC
file 2 contains
DEF

so my outputfile.txt should look like
ABC
DEF

Thanks

RE: move search contents to a text.file

(OP)
Thanks PHV,
I am getting following error.

ksh: /usr/bin/cat: arg list too long

how to fix ?

Thanks,

RE: move search contents to a text.file

in that case use find and run cat foundName >> outfilename as an exec parameter to 'merge' the contents

CODE --> shell

find -name 'filespec' -exec cat {} >> outfile \; 

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: move search contents to a text.file

(OP)
Hi Chris,

I Tried this
cat filename* > myoutput.txt and it copied all files with that specific filenames to myoutput.txt. thanks.

Hi PHV,

When I try your command, I am getting error with every cat that cant open file name.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close