Solved

simple shell question

Posted on 2011-02-13
2
313 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

808 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