<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: awk substitution help in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040053#M95676</link>
    <description>issue I have with the systems here is that there has been no file archiving on some audit and transaction files so accross 5 filesystems there is over 40 million files no larger than 1mb, I have been given the thankless task of sorting it out.&lt;BR /&gt;&lt;BR /&gt;All the tips and tricks you guys have provided will be implemented once I have a policy - main issue is the files are dumped all over the place and most of the data cannot be deleted!</description>
    <pubDate>Fri, 13 Apr 2007 10:16:27 GMT</pubDate>
    <dc:creator>lawrenzo_1</dc:creator>
    <dc:date>2007-04-13T10:16:27Z</dc:date>
    <item>
      <title>awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040048#M95671</link>
      <description>hi,&lt;BR /&gt;&lt;BR /&gt;I am trying to change a field within a file using awk and am having some difficulty ...&lt;BR /&gt;&lt;BR /&gt;the file dates are displayed &lt;BR /&gt;&lt;BR /&gt;file month year&lt;BR /&gt;a    Sept  2006&lt;BR /&gt;b    Oct   23:30&lt;BR /&gt;b1   Nov   16:00&lt;BR /&gt;c    Dec   12:20&lt;BR /&gt;d    Jan   02:13&lt;BR /&gt;e    Feb   14:23&lt;BR /&gt;f    Mar   22:01&lt;BR /&gt;g    Apr   04:34&lt;BR /&gt;&lt;BR /&gt;I want to chage the time stamp to display the where oct,nov,dec will be 2006 and jan,feb,mar,apr to display 2007&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;here is the syntax I have worked out so far:&lt;BR /&gt;&lt;BR /&gt;awk '{filename=$1; month=$2; year=$3}; {if (substr(year,1,3) !=200) {year="unknown"}} {print filename,month,year}' datesort.lst&lt;BR /&gt;&lt;BR /&gt;This will change the field to unknown.&lt;BR /&gt;&lt;BR /&gt;I can pipe this into another file and run something similar several times to change the month however I am sure there is a much more effectient way.&lt;BR /&gt;&lt;BR /&gt;any ideas?&lt;BR /&gt;&lt;BR /&gt;Thanks &lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Fri, 13 Apr 2007 09:53:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040048#M95671</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-04-13T09:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040049#M95672</link>
      <description>Not sure I understand...you want to replace the time stamp with the year then why is the script replacing it with "unknown". A sample of the desired output would help.&lt;BR /&gt;&lt;BR /&gt;~thanks</description>
      <pubDate>Fri, 13 Apr 2007 10:00:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040049#M95672</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-04-13T10:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040050#M95673</link>
      <description>Hey Chris,&lt;BR /&gt;&lt;BR /&gt;"what is the real problem you are trying to solve?"&lt;BR /&gt;&lt;BR /&gt;We caught a glimps of that in your other posting.&lt;BR /&gt;From there I would encourage you NOT to use the ls -l output with the date problem presented here. Or if you must use the listing, go to the file and stat it to get teh date rather then parse.&lt;BR /&gt;&lt;BR /&gt;Still, if you want to move forward in this direction consder the following awk example.&lt;BR /&gt;Adapt to your detail needs.&lt;BR /&gt;&lt;BR /&gt;awk '$3 ~ /:/ {$3=2007} {print}' datesort.lst&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Apr 2007 10:03:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040050#M95673</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-04-13T10:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040051#M95674</link>
      <description>Hi Chris:&lt;BR /&gt;&lt;BR /&gt;# perl -pe 's{(oct|nov|dec)\s+(\d\d:\d\d)}{$1 2006}i;s{(jan|feb|mar|apr)\s+(\d\d:\d\d)}{$1 2007}i' datesort.lst&lt;BR /&gt;&lt;BR /&gt;...and if you want to update, in-place do:&lt;BR /&gt;&lt;BR /&gt;# perl -pi.old -e 's{(oct|nov|dec)\s+(\d\d:\d\d)}{$1 2006}i;s{(jan|feb|mar|apr)\s+(\d\d:\d\d)}{$1 2007}i' datesort.lst&lt;BR /&gt;'s &lt;BR /&gt;&lt;BR /&gt;...which preserves the oritinal file with a suffix of ".old".&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Apr 2007 10:06:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040051#M95674</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-04-13T10:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040052#M95675</link>
      <description>ok inputted the incorrect string ...&lt;BR /&gt;&lt;BR /&gt;first I came up with this:&lt;BR /&gt;&lt;BR /&gt;awk '{filename=$9; month=$7; year=$8}; {if (substr(year,1,3) !=200) {year="unknown"}} {print filename,month,year}' toberemoved.lst&lt;BR /&gt;&lt;BR /&gt;this gave me the output &lt;BR /&gt;&lt;BR /&gt;dailyReturns03022007.unl Feb unknown&lt;BR /&gt;dailyReturns03032006.unl Mar 2006&lt;BR /&gt;dailyReturns03042006.unl Apr 2006&lt;BR /&gt;dailyReturns03052006.unl May 2006&lt;BR /&gt;dailyReturns03062006.unl Jun 2006&lt;BR /&gt;dailyReturns03072006.unl Jul 2006&lt;BR /&gt;dailyReturns03082006.unl Aug 2006&lt;BR /&gt;dailyReturns03092006.unl Sep 2006&lt;BR /&gt;dailyReturns03102006.unl Oct 2006&lt;BR /&gt;dailyReturns03112005.unl Nov 2005&lt;BR /&gt;dailyReturns03112006.unl Nov unknown&lt;BR /&gt;dailyReturns03122006.unl Dec unknown&lt;BR /&gt;dailyReturns04012006.unl Jan 2006&lt;BR /&gt;dailyReturns04012007.unl Jan unknown&lt;BR /&gt;dailyReturns04022006.unl Feb 2006&lt;BR /&gt;dailyReturns04022007.unl Feb unknown&lt;BR /&gt;dailyReturns04032006.unl Mar 2006&lt;BR /&gt;&lt;BR /&gt;the original toberemoved file looked like this&lt;BR /&gt;&lt;BR /&gt;-rw-r--r--   1 2865     staff            38 25 Oct 2005  AST0000002.csv&lt;BR /&gt;-rw-r--r--   1 2865     staff            37 04 Nov 2005  AST0000003.csv&lt;BR /&gt;-rw-r--r--   1 2865     staff            37 07 Nov 2005  AST0000004.csv&lt;BR /&gt;-rw-r--r--   1 950      staff            43 21 Sep 2006  AST0000011&lt;BR /&gt;-rw-r--r--   1 950      staff            43 28 Sep 2006  AST0000012&lt;BR /&gt;-rw-r--r--   1 950      staff            43 29 Sep 2006  AST0000013&lt;BR /&gt;-rw-r--r--   1 950      staff            43 05 Oct 2006  AST0000014&lt;BR /&gt;-rw-r--r--   1 950      staff            43 05 Oct 2006  AST0000015&lt;BR /&gt;-rw-r--r--   1 950      staff            43 17 Oct 18:42 AST0000016&lt;BR /&gt;-rw-r--r--   1 950      staff            43 17 Oct 18:42 AST0000017&lt;BR /&gt;-rw-r--r--   1 950      staff            43 18 Oct 08:41 AST0000018&lt;BR /&gt;-rw-r--r--   1 950      staff            43 18 Oct 08:41 AST0000019&lt;BR /&gt;-rw-r--r--   1 950      staff            43 18 Oct 14:42 AST0000020&lt;BR /&gt;etc&lt;BR /&gt;etc&lt;BR /&gt;&lt;BR /&gt;I thought it may be easier piping the output with unknown to another file then work on unknown to either display 2006 for last year months and 2007 for this year but I am sure you can do this in one hit.&lt;BR /&gt;&lt;BR /&gt;so&lt;BR /&gt;&lt;BR /&gt;I have come up with:&lt;BR /&gt;&lt;BR /&gt;awk '{filename=$1; month=$2; year=$3}; {if (substr(month,1,3) !=^[OND]) {year="2007"}} {print filename,month,year}' datesort.lst.unkown&lt;BR /&gt;&lt;BR /&gt;which changes the 3rd field to 2007 for all files.&lt;BR /&gt;&lt;BR /&gt;:(&lt;BR /&gt;&lt;BR /&gt;I am working through an awk book by Alfred V. Aho which is pretty slow going especially when I am working in support so any help / pointers will help.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Fri, 13 Apr 2007 10:08:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040052#M95675</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-04-13T10:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040053#M95676</link>
      <description>issue I have with the systems here is that there has been no file archiving on some audit and transaction files so accross 5 filesystems there is over 40 million files no larger than 1mb, I have been given the thankless task of sorting it out.&lt;BR /&gt;&lt;BR /&gt;All the tips and tricks you guys have provided will be implemented once I have a policy - main issue is the files are dumped all over the place and most of the data cannot be deleted!</description>
      <pubDate>Fri, 13 Apr 2007 10:16:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040053#M95676</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-04-13T10:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040054#M95677</link>
      <description>Here is something real close to what you did. Rather then lookgin for 'known months' would it not be safer to look for something that looks like a timestamp instead of a year?&lt;BR /&gt;&lt;BR /&gt;$ awk '{filename=$9; month=$7; year=$8}; year ~ /:/ { year=2007} {print filename,month,year}' orig&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;That's really 3 code block, 1 conditional in the middle lookgin for the match.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It can also be written as:&lt;BR /&gt;&lt;BR /&gt;$ awk '{filename=$9; month=$7; year = /:/? 2007 : $8; print filename,month,year}' x&lt;BR /&gt;&lt;BR /&gt;Just 1 codeblock with a conditional assignment:&lt;BR /&gt;&lt;BR /&gt;year = /:/? 2007 : $8; &lt;BR /&gt;&lt;BR /&gt;Read as: &lt;BR /&gt;&lt;BR /&gt;If there is a ":" anywhere on the line then year becomes 2007 (should be 'current year') else year becomes field 8.&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Apr 2007 10:19:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040054#M95677</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-04-13T10:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040055#M95678</link>
      <description>Thanks all for the help,&lt;BR /&gt;&lt;BR /&gt;I may go with the perl solution and be done with it however would prefer to understand the syntax so Hein this works but there are months from 2006 with the time stamp (oct,nov,dec)</description>
      <pubDate>Fri, 13 Apr 2007 10:36:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040055#M95678</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-04-13T10:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040056#M95679</link>
      <description>&amp;gt;If there is a ":" anywhere on the line then year becomes 2007 (should be &amp;gt;'current year') else year becomes field 8.&lt;BR /&gt;&lt;BR /&gt;Not neccessarily see ls(1) for details. Any past date within six months of the current date will be printed as a "month timestamp" instead of the "month year" format.</description>
      <pubDate>Fri, 13 Apr 2007 10:47:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040056#M95679</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-04-13T10:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040057#M95680</link>
      <description>Hi (again) Chris:&lt;BR /&gt;&lt;BR /&gt;The Perl snippet is largely regular expressions as Perl does them best:&lt;BR /&gt;&lt;BR /&gt;# perl -pe 's{(oct|nov|dec)\s+(\d\d:\d\d)}{$1 2006}i;s{(jan|feb|mar|apr)\s+(\d\d:\d\d)}{$1 2007}i' datesort.lst&lt;BR /&gt;&lt;BR /&gt;The '-p' switch creates a read-loop for the file specified as an argument to the script.&lt;BR /&gt;&lt;BR /&gt;The 's' says "substitute" and the trailing "i" says to find matches to substitute case-insensitvely.&lt;BR /&gt;&lt;BR /&gt;The (oct|nov|dec) notation says match a sequence of any of these three-character strings.  The '\s+' says that one or more whitespace characters must follow.  The '\d' stands for a digit.  By enclosing things in parenthesis we can remember the pieces of what we match.  The first group is referenced as $1; the second as $2, etc. Then, we can back-reference the parts of what we match create the substitution.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 13 Apr 2007 10:52:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040057#M95680</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-04-13T10:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040058#M95681</link>
      <description>ok thanks James</description>
      <pubDate>Fri, 13 Apr 2007 10:57:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040058#M95681</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-04-13T10:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040059#M95682</link>
      <description>&lt;!--!*#--&gt;Chris&amp;gt;&amp;gt;  Hein this works but there are months from 2006 with the time stamp (oct,nov,dec)&lt;BR /&gt;&lt;BR /&gt;Yes. Duh. What was I thinking?&lt;BR /&gt;&lt;BR /&gt;Ultimately you'll be better of picking up perl, specially for easy jobs to learn, but just to correct my bad advice her it an awk variant:&lt;BR /&gt;&lt;BR /&gt;awk '{filename=$9; month=$7; year=$8; if (year ~ /:/){year = (month ~ /Sep|Oct|Nov|Dec/)? 2006 : 2007} print filename,month,year}' orig&lt;BR /&gt;&lt;BR /&gt;In slow motion...&lt;BR /&gt;&lt;BR /&gt;awk '{&lt;BR /&gt;filename=$9; &lt;BR /&gt;month=$7; &lt;BR /&gt;year=$8; &lt;BR /&gt;if (year ~ /:/){&lt;BR /&gt;   year = (month ~ /Sep|Oct|Nov|Dec/)? 2006 : 2007&lt;BR /&gt;   }&lt;BR /&gt;print filename,month,year&lt;BR /&gt;}' orig&lt;BR /&gt;&lt;BR /&gt;Hein&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Apr 2007 11:08:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040059#M95682</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-04-13T11:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040060#M95683</link>
      <description>great stuff thanks all!&lt;BR /&gt;&lt;BR /&gt;Chris.</description>
      <pubDate>Mon, 16 Apr 2007 02:15:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040060#M95683</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-04-16T02:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: awk substitution help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040061#M95684</link>
      <description>;)</description>
      <pubDate>Mon, 16 Apr 2007 02:16:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-substitution-help/m-p/5040061#M95684</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2007-04-16T02:16:30Z</dc:date>
    </item>
  </channel>
</rss>

