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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merge multiple files into one with a specific format

Status
Not open for further replies.

GiovanniC

Technical User
Nov 5, 2001
15
AU
Hi folks,

I've got one of those "merge files" question. What I have is literally thousands of files, each containing a text string (lets call it "XXXXXXXXXXXXXXX"; "YYYYYYY" etc). The string may be on one or more lines in the file. Each file has a different file name, and all files are contained within a single directory.

The contents of the merged file needs to have the following format (the '>' sign is important):


>FileName1
XXXXXXXXXXXXXXXXXXXXXXXXXX
>FileName2
YYYYYYYYYYY
>FileName3
AAAAAAAAAAAAAAAAAAAAAA
>FileName4
DDDDDDDDDDDDDDDDRRRRRRRRRRRRR

Any suggestions for a quick and easy merge?

Giovanni
 
Code:
awk '{ if (last != FILENAME) { print FILENAME; last = FILENAME }; gsub(/[": ]/, ""); print }' *

. Mac for productivity
.. Linux for developement
... Windows for solitaire
 
Hi xmb,

Thanks for that quick response. It does what I want it to do.

Cheers,

Giovanni
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top