Solved

simple shell question

Posted on 2011-02-13
2
312 Views
Last Modified: 2012-08-13
I have files in the following format.
hits0114.txt   (0114 means January 14).
hits0115.txt
hits0116.txt

and so on.

inside each file I have two columns, like this

  94125 0
   8063 -1
  41548 10
   5182 4
  29374 7
   2913 8
   3373 9


How would I concatenate these files and create one file all_hits.txt where

the first column is the date in ddmm format (same as above)
and the second and the third columns are the two columns mentioned above
0
Comment
Question by:aturetsky
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 34885450
perl -pe 's#^#@{[$ARGV=~/(\d{4})\./]} #' hits*.txt < all_hits.txt
0
 
LVL 1

Author Comment

by:aturetsky
ID: 34885473
perfect - just what I asked for!

just to notch it up a bit - is it possible in the output file to put the date in a mm/dd format - i.e. 01/30
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now