Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

move search contents to a text.file

Status
Not open for further replies.

jf2014

Technical User
Jun 29, 2014
4
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
 
1) direct the command output to a file

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

or
Code:
>> filename
to append the output to an existing file.


2)

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
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
 
Code:
cat $([i][b]your search result command here[/b][/i]) >outputfile.txt
Code:
cat `[i][b]your search result command here[/b][/i]` >outputfile.txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV,
I am getting following error.

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

how to fix ?

Thanks,

 
Code:
(your search result command here | xargs cat) >outputfile.txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
in that case use find and run cat foundName >> outfilename as an exec parameter to 'merge' the contents

Code:
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
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top