<?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: script help, string matching form new file in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612617#M104844</link>
    <description>also I need the omitted lines in the result.&lt;BR /&gt;patrick.</description>
    <pubDate>Wed, 14 Sep 2005 21:21:07 GMT</pubDate>
    <dc:creator>patrick xi</dc:creator>
    <dc:date>2005-09-14T21:21:07Z</dc:date>
    <item>
      <title>script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612603#M104830</link>
      <description>Dear friends,&lt;BR /&gt;&lt;BR /&gt;I need a shell script to process several files, they are FileA, FileB, FileC, FileD,...&lt;BR /&gt;&lt;BR /&gt;1.feature of the file&lt;BR /&gt;     .each have 600 columns&lt;BR /&gt;     .lines from 2nd line to bottom are useful&lt;BR /&gt;     .from column 2-10 is P_name, column 60-80 is Description&lt;BR /&gt;2.demands&lt;BR /&gt;     .trim each file to TA, TB, TC, ... formed by first unique P_name lines&lt;BR /&gt;     .merge TA line to TB if P_name in that line of TA is not in TB, this make file M1, then M2 is between TB and TC, M3 is between TC and TD,...&lt;BR /&gt;&lt;BR /&gt;what I need is M1, M2, M3, ... , could you help me? &lt;BR /&gt;Hope I explained well and thank you in advance.&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;Patrick</description>
      <pubDate>Fri, 26 Aug 2005 04:19:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612603#M104830</guid>
      <dc:creator>patrick xi</dc:creator>
      <dc:date>2005-08-26T04:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612604#M104831</link>
      <description>for file in `ls FILE*`&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; logfile="T$(echo $file | sed 's/.*\(.\)$/\1/')"&lt;BR /&gt; awk '(NR!=1) { for (i=2;i&amp;lt;=20;i++) { print $i; } }' $file | sort -u &amp;gt; $logfile&lt;BR /&gt;   &lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;It will create TA, TB, TC files.&lt;BR /&gt;&lt;BR /&gt;You can  create M1, M2, M3 files as,&lt;BR /&gt;&lt;BR /&gt;grep -vf TA &amp;lt; TB &amp;gt; M1&lt;BR /&gt;&lt;BR /&gt;like that.&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Fri, 26 Aug 2005 10:07:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612604#M104831</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-08-26T10:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612605#M104832</link>
      <description>Hello Muthukumar,&lt;BR /&gt;Thank you for taking the time.&lt;BR /&gt;but the result seems not what I want.&lt;BR /&gt;1. I need the whole line, not only the P_name.&lt;BR /&gt;2. The script is defined to work on column 2 to 10, but I found in result I got column 165 to 176, I don't know why. Too many columns?&lt;BR /&gt;3. How can I start from 4th or 6th line? ( words above are not very correct: ".lines from 2nd line to bottom are useful", because source file varied, I have to change the configure from time to time)&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;Patrick&lt;BR /&gt;</description>
      <pubDate>Sat, 27 Aug 2005 06:39:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612605#M104832</guid>
      <dc:creator>patrick xi</dc:creator>
      <dc:date>2005-08-27T06:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612606#M104833</link>
      <description>I made a test file named fileA, content is:&lt;BR /&gt;1234567890123456789012345678901234567890&lt;BR /&gt; testfile1     desc            trees&lt;BR /&gt; testfile1     desc            apple&lt;BR /&gt; partnume1     desc            orange&lt;BR /&gt; testfile1     desc            table&lt;BR /&gt; partnume2     desc            12345&lt;BR /&gt; partnume9     desc            na&lt;BR /&gt; partnume7     desc            na&lt;BR /&gt;&lt;BR /&gt;the result TA should be :&lt;BR /&gt; testfile1     desc            trees&lt;BR /&gt; partnume1     desc            orange&lt;BR /&gt; partnume2     desc            12345&lt;BR /&gt; partnume7     desc            na&lt;BR /&gt; partnume9     desc            na&lt;BR /&gt;</description>
      <pubDate>Sat, 27 Aug 2005 07:01:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612606#M104833</guid>
      <dc:creator>patrick xi</dc:creator>
      <dc:date>2005-08-27T07:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612607#M104834</link>
      <description>Hi,&lt;BR /&gt;If this problem should not be too complex you need to sort the file using the first field as key (is it any problem).&lt;BR /&gt;sort -k 1 &lt;FILE&gt; &amp;gt;outfile&lt;BR /&gt;then , try awk&lt;BR /&gt;&lt;BR /&gt;cat outfile |awk ' $1 != old { print ; old=$1}'&lt;BR /&gt;&lt;/FILE&gt;</description>
      <pubDate>Sat, 27 Aug 2005 09:14:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612607#M104834</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2005-08-27T09:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612608#M104835</link>
      <description>hi Leif, thank you for reply.&lt;BR /&gt;&lt;BR /&gt;as in "demands", the P_name is from column 2 to 10, sometimes it contains several blanks, so several fields.</description>
      <pubDate>Sun, 28 Aug 2005 00:28:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612608#M104835</guid>
      <dc:creator>patrick xi</dc:creator>
      <dc:date>2005-08-28T00:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612609#M104836</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;One method I have sometimes used is to translate blanks to a caracters, not used as field separators. In your case, a "qiuck and dirty" solution could look something like:&lt;BR /&gt;(not sure what you want to do with column 1)&lt;BR /&gt; &lt;BR /&gt;cut -c 1 infile &amp;gt;tmp1&lt;BR /&gt;cut -c 2-10 infile &amp;gt;tmp2&lt;BR /&gt;cut -c 11- infile &amp;gt;tmp3&lt;BR /&gt;tr " " "_" &lt;TMP1&gt;tmp4&lt;BR /&gt;paste -d " " tmp1 tmp4 tmp2 &amp;gt;tmp5&lt;BR /&gt;&lt;BR /&gt;Now, column 1 and 2-10 should be two field separated by blanks. Blanks in pos 2-10 in the original file is translated to "_".&lt;BR /&gt;&lt;BR /&gt;Now you can try my previous solution (but using $2 instead of $1).&lt;BR /&gt;&lt;BR /&gt;After that you can use the same method as above for translating "-" to blanks.&lt;/TMP1&gt;</description>
      <pubDate>Sun, 28 Aug 2005 06:12:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612609#M104836</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2005-08-28T06:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612610#M104837</link>
      <description>the sample file fileA is not displayed well, continuous blanks are displayed as one. so I put it in attachment...</description>
      <pubDate>Sun, 28 Aug 2005 19:35:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612610#M104837</guid>
      <dc:creator>patrick xi</dc:creator>
      <dc:date>2005-08-28T19:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612611#M104838</link>
      <description>Hi,&lt;BR /&gt;The attached file gives an better idea about how your files look like.&lt;BR /&gt;&lt;BR /&gt;I assume the first field ia always a blank so we can ignore it (it is easy to recreate in the final file if you want).&lt;BR /&gt;I also assume there is one or more blanks in pos 11- .&lt;BR /&gt;I am also afraid that we must sort the file if it should be possible to solve without using a full database tool. Is it OK ?&lt;BR /&gt;&lt;BR /&gt;In the following ex. you should type a blank instead of &lt;SPACE&gt;. I have done so as blank dont show correct here.&lt;BR /&gt;Try the following on one of your files.&lt;BR /&gt;&lt;BR /&gt;cut -c 2-10 infile &amp;gt;tmp1&lt;BR /&gt;cut -c 11- infile &amp;gt;tmp2&lt;BR /&gt;tr "&lt;SPACE&gt;" "_" &lt;TMP1&gt;tmp3&lt;BR /&gt;paste -d"\0" tmp3 tmp2 &amp;gt;tmp4&lt;BR /&gt;sort -k 1 tmp4 &amp;gt;tmp5&lt;BR /&gt;awk ' $1 != old { print ; old=$1}' |tr "_" "&lt;SPACE&gt;"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Does the output look like what you want in the TA file ?&lt;BR /&gt;&lt;/SPACE&gt;&lt;/TMP1&gt;&lt;/SPACE&gt;&lt;/SPACE&gt;</description>
      <pubDate>Mon, 29 Aug 2005 03:32:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612611#M104838</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2005-08-29T03:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612612#M104839</link>
      <description>First part of creating TA, TB files can be done as,&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;&lt;BR /&gt;# Enter user input&lt;BR /&gt;LINESTART=2&lt;BR /&gt;&lt;BR /&gt;for file in `ls FILE*`&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;  logfile="T$(echo $file | sed 's/.*\(.\)$/\1/')"&lt;BR /&gt;  &lt;BR /&gt;  for lno in `awk -v ln=$LINESTART '(NR!=ln) { print NR,$1 }' ${file} | sort -uk 2,20 | cut -d" " -f1 | sort`&lt;BR /&gt;  do&lt;BR /&gt;    sed -e "$lno!d" $file &amp;gt; $logfile&lt;BR /&gt;  done&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;## Change LINESTART to specify from 2nd line to last or 6th line to last line.&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Mon, 29 Aug 2005 06:36:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612612#M104839</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-08-29T06:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612613#M104840</link>
      <description>Second part of merge TA line to TB if P_name in that line of TA is not in TB like that,&lt;BR /&gt;&lt;BR /&gt;set -A ARR `ls -1 File*`&lt;BR /&gt;&lt;BR /&gt;index=0&lt;BR /&gt;findex=1&lt;BR /&gt;&lt;BR /&gt;while [[ $index -lt ${#ARR} ]]&lt;BR /&gt;do&lt;BR /&gt;  grep -vf ${ARR[$index]} ${ARR[$index+1]} &amp;gt;M${findex}&lt;BR /&gt;  let index=index+2&lt;BR /&gt;  let findex=findex+1&lt;BR /&gt;done  &lt;BR /&gt;&lt;BR /&gt;# Add this and try it&lt;BR /&gt;&lt;BR /&gt;hth.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Aug 2005 06:49:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612613#M104840</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-08-29T06:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612614#M104841</link>
      <description>hi, Leif and Muthukumar,&lt;BR /&gt;&lt;BR /&gt;thank you.&lt;BR /&gt;&lt;BR /&gt;according to leif's solution, it did work and gave a better result, but not very exactly meet the demand, like how to start from the 2nd or 4th line to process?&lt;BR /&gt;&lt;BR /&gt;according to Muthukumar's solution, I tested it with my sample file, the result is not what I want. But your script is what I'm expecting to be like. Hope this will work.&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;Patrick</description>
      <pubDate>Wed, 14 Sep 2005 20:30:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612614#M104841</guid>
      <dc:creator>patrick xi</dc:creator>
      <dc:date>2005-09-14T20:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612615#M104842</link>
      <description>Hi Patrick:&lt;BR /&gt;&lt;BR /&gt;If Leif's solution meets your needs and you only want to begin after (for instance, line #2) change his 'awk' to read:&lt;BR /&gt;&lt;BR /&gt;# awk '{if (NR&amp;gt;2) {$1 !=old;print;old=$1}}' | tr "_" "&lt;SPACE&gt;"&lt;BR /&gt;&lt;BR /&gt;'awk's NR variable provides the line-number of the file being processed.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;/SPACE&gt;</description>
      <pubDate>Wed, 14 Sep 2005 20:49:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612615#M104842</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-09-14T20:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612616#M104843</link>
      <description>hi, JRF, &lt;BR /&gt;nice to meet you.&lt;BR /&gt;&lt;BR /&gt;in Leif's script, the lines are already sorted before awk. So the line sequence is changed.&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;Patrick</description>
      <pubDate>Wed, 14 Sep 2005 21:15:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612616#M104843</guid>
      <dc:creator>patrick xi</dc:creator>
      <dc:date>2005-09-14T21:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: script help, string matching form new file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612617#M104844</link>
      <description>also I need the omitted lines in the result.&lt;BR /&gt;patrick.</description>
      <pubDate>Wed, 14 Sep 2005 21:21:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-help-string-matching-form-new-file/m-p/3612617#M104844</guid>
      <dc:creator>patrick xi</dc:creator>
      <dc:date>2005-09-14T21:21:07Z</dc:date>
    </item>
  </channel>
</rss>

