<?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 help in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908384#M96799</link>
    <description>i know you asked for help using awk.&lt;BR /&gt;&lt;BR /&gt;but, there are several perl modules written for handling csv files.  Just a suggestion, use code that has already been written and tested instead of creating your own.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.perlmeme.org/tutorials/parsing_csv.html" target="_blank"&gt;http://www.perlmeme.org/tutorials/parsing_csv.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.interopp.org/ncci/man/CSV.htm" target="_blank"&gt;http://www.interopp.org/ncci/man/CSV.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://search.cpan.org/search?query=csv&amp;amp;mode=all" target="_blank"&gt;http://search.cpan.org/search?query=csv&amp;amp;mode=all&lt;/A&gt;</description>
    <pubDate>Thu, 07 Dec 2006 00:14:03 GMT</pubDate>
    <dc:creator>curt larson_1</dc:creator>
    <dc:date>2006-12-07T00:14:03Z</dc:date>
    <item>
      <title>awk help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908376#M96791</link>
      <description>i have a csv file like&lt;BR /&gt;"ab",12345,456,"home ahi","new one","get that me",45678,"new",123,"mnw",45,"mnuens"&lt;BR /&gt;"ab",12345,456,"home ahi","new one","get that me",45678,"new",123,"mnw",45,"mnuens","kil je"&lt;BR /&gt;&lt;BR /&gt;I want the fields where a character fields contains double quotes" (in between the field not the " which encloses the field)&lt;BR /&gt;&lt;BR /&gt;Please help me out.</description>
      <pubDate>Wed, 06 Dec 2006 00:54:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908376#M96791</guid>
      <dc:creator>viseshu</dc:creator>
      <dc:date>2006-12-06T00:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: awk help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908377#M96792</link>
      <description>&lt;!-- !*# --&gt;&lt;P&gt;I don't see any entry that contains embedded double quotes??&lt;BR /&gt;&lt;BR /&gt;This script assume that comma isn't embedded. It also assume that double quote isn't embedded in a non-quoted string.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;awk -F"," '&lt;BR /&gt;function check_field(i, ff) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; len = length(ff)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (substr(ff, 1, 1) == "\"" &amp;amp;&amp;amp; substr(ff, len, 1) == "\"") {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (index(substr(ff,2,len-2), "\"") != 0) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Found embedded double quote"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "record:", NR, " field:", i, ":" ff ":"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;}&lt;BR /&gt;{&lt;BR /&gt;# check each field for embedded double quotes&lt;BR /&gt;for (i=1; i &amp;lt;= NF; ++i) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; check_field(i, $i)&lt;BR /&gt;}&lt;BR /&gt;}' itrc_cvs.in&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2011 00:55:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908377#M96792</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-10-24T00:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: awk help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908378#M96793</link>
      <description>Dennis, it may happen like a double quote may be missing at the start or end of the field.. Then will it works fine????</description>
      <pubDate>Wed, 06 Dec 2006 03:16:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908378#M96793</guid>
      <dc:creator>viseshu</dc:creator>
      <dc:date>2006-12-06T03:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: awk help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908379#M96794</link>
      <description>&lt;!-- !*# --&gt;&lt;P&gt;No, try this version. Note: it doesn't check for quotes being balanced.&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;awk -F"," '&lt;BR /&gt;function check_field(i, ff) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; len = length(ff)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # strip off any double quotes&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (substr(ff, len, 1) == "\"")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --len&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; start=1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (substr(ff, 1, 1) == "\"") {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; start=2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --len&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (index(substr(ff,start,len), "\"") != 0) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Found embedded double quote"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "record:", NR, " field:", i, ":" ff ":"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;{&lt;BR /&gt;# check each field for embedded double quotes&lt;BR /&gt;for (i=1; i &amp;lt;= NF; ++i) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; check_field(i, $i)&lt;BR /&gt;}&lt;BR /&gt;}' itrc_cvs.in&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2011 00:56:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908379#M96794</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-10-24T00:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: awk help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908380#M96795</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I would divide this request into two parts:&lt;BR /&gt;1) check for balanced quoting&lt;BR /&gt;2) generate the requested output&lt;BR /&gt;&lt;BR /&gt;Solution 1)&lt;BR /&gt;awk -F, -v qu='"' '{for(i=1;i&amp;lt;=NF;i++) {if(! index($i,qu)) continue&lt;BR /&gt;m=match($i,qu".*"qu)&lt;BR /&gt;if(m) { if(length($i)==RLENGTH) continue&lt;BR /&gt;printf("Err: line=%d f=%d data outside quotes:%s:\n",NR,i,$i)}&lt;BR /&gt;else printf("Err: line=%d f=%d unbalanced quotes:%s:\n",NR,i,$i)}}'&lt;BR /&gt;&lt;BR /&gt;Feeding this data&lt;BR /&gt;1234,aa","aa bb","dd"hh,"bb,456&lt;BR /&gt;would create&lt;BR /&gt;Err: line=1 f=2 unbalanced quotes:aa":&lt;BR /&gt;Err: line=1 f=4 data outside quotes:"dd"hh:&lt;BR /&gt;Err: line=1 f=5 unbalanced quotes:"bb:&lt;BR /&gt;&lt;BR /&gt;Solution 2)&lt;BR /&gt;awk -F, -v qu='"' '{out=0; for(i=1;i&amp;lt;=NF;i++) {if(! index($i,qu)) continue&lt;BR /&gt;if (match($i,qu".*"qu) &amp;amp;&amp;amp; (length($i)==RLENGTH)) {if(out) printf(FS);out++;printf(substr($i,2,RLENGTH-2))}}&lt;BR /&gt;if(out) printf("\n")}' above.csv&lt;BR /&gt;&lt;BR /&gt;would create this output (with above data)&lt;BR /&gt;ab,home ahi,new one,get that me,new,mnw,mnuens&lt;BR /&gt;ab,home ahi,new one,get that me,new,mnw,mnuens,kil je&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Wed, 06 Dec 2006 09:30:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908380#M96795</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-12-06T09:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: awk help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908381#M96796</link>
      <description>&lt;!--!*#--&gt;Another way to do it would to be to count the number of times double-quotes appear in the fields. If the count is other than zero (numeric field) or two (field punctuated by double-quotes) then print that field. If the field is zero then do nothing. If count==2, print the field if quotes aren't at the ends.&lt;BR /&gt;&lt;BR /&gt;See the awk script below...&lt;BR /&gt;&lt;BR /&gt;awk -F, '{&lt;BR /&gt;  for (i=1;i&amp;lt;=NF;++i) {&lt;BR /&gt;    f=$i&lt;BR /&gt;    s=gsub("\"","",f)&lt;BR /&gt;    if (s) {&lt;BR /&gt;      if (s==2) {&lt;BR /&gt;        if ($i!~/^".*"$/)&lt;BR /&gt;          print $i&lt;BR /&gt;      }&lt;BR /&gt;      else&lt;BR /&gt;        print $i&lt;BR /&gt;    }&lt;BR /&gt;  }&lt;BR /&gt;}' file</description>
      <pubDate>Wed, 06 Dec 2006 11:28:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908381#M96796</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-12-06T11:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: awk help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908382#M96797</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;a simple approach based on an idea similar to Sandman's:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset -i POS=0 NUMBER=0&lt;BR /&gt;&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;        while [ POS -lt ${#LINE} ]&lt;BR /&gt;                do&lt;BR /&gt;                        POS=$POS+1&lt;BR /&gt;                        KARAK=$(echo ${LINE} | cut -c $POS)&lt;BR /&gt;                        if [ "$KARAK" = "\"" ]&lt;BR /&gt;                        then&lt;BR /&gt;                                NUMBER=$(( $NUMBER + 1 ))&lt;BR /&gt;                                KARAK=" "&lt;BR /&gt;                        fi&lt;BR /&gt;                        let DECISION=NUMBER%2&lt;BR /&gt;                        if [ "$DECISION" != 0 ]&lt;BR /&gt;                        then&lt;BR /&gt;                                echo "$KARAK\c"&lt;BR /&gt;                        fi&lt;BR /&gt;                done&lt;BR /&gt;                echo ""&lt;BR /&gt;                POS=0&lt;BR /&gt;                NUMBER=0&lt;BR /&gt;done &amp;lt;$1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Run it using your inputfile as $1&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;</description>
      <pubDate>Wed, 06 Dec 2006 11:42:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908382#M96797</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2006-12-06T11:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: awk help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908383#M96798</link>
      <description>Is it possible to enclose the number fields with double quotes????(6,10,19 fields)&lt;BR /&gt;Presently double quotes are not enclosed with ""</description>
      <pubDate>Wed, 06 Dec 2006 23:35:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908383#M96798</guid>
      <dc:creator>viseshu</dc:creator>
      <dc:date>2006-12-06T23:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: awk help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908384#M96799</link>
      <description>i know you asked for help using awk.&lt;BR /&gt;&lt;BR /&gt;but, there are several perl modules written for handling csv files.  Just a suggestion, use code that has already been written and tested instead of creating your own.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.perlmeme.org/tutorials/parsing_csv.html" target="_blank"&gt;http://www.perlmeme.org/tutorials/parsing_csv.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.interopp.org/ncci/man/CSV.htm" target="_blank"&gt;http://www.interopp.org/ncci/man/CSV.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://search.cpan.org/search?query=csv&amp;amp;mode=all" target="_blank"&gt;http://search.cpan.org/search?query=csv&amp;amp;mode=all&lt;/A&gt;</description>
      <pubDate>Thu, 07 Dec 2006 00:14:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908384#M96799</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2006-12-07T00:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: awk help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908385#M96800</link>
      <description>The numeric fields can have double-quotes and they will be treated the same as the non-numeric fields and irrespective of whether the field contains only double-quotes.&lt;BR /&gt;&lt;BR /&gt;~hope it helps</description>
      <pubDate>Thu, 07 Dec 2006 00:41:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908385#M96800</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-12-07T00:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: awk help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908386#M96801</link>
      <description>Sandy,&lt;BR /&gt;  Im generally asking this help... i need it in other script.Please help me out</description>
      <pubDate>Thu, 07 Dec 2006 01:04:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908386#M96801</guid>
      <dc:creator>viseshu</dc:creator>
      <dc:date>2006-12-07T01:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: awk help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908387#M96802</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;if you generally want to enclose fields with quotes and want to output all (valid) fields, modify my "Solution 2":&lt;BR /&gt;Solution 2b)&lt;BR /&gt;awk -F, -v qu='"' '{out=0; for(i=1;i&amp;lt;=NF;i++) {if(out) printf(FS);out++&lt;BR /&gt;if(! index($i,qu)) {printf("%s%s%s",qu,$i,qu); continue }&lt;BR /&gt;if (match($i,qu".*"qu) &amp;amp;&amp;amp; (length($i)==RLENGTH)) printf($i)}&lt;BR /&gt;if(out) printf("\n")}' above.csv&lt;BR /&gt;&lt;BR /&gt;mfG Peter&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Dec 2006 02:42:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908387#M96802</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-12-07T02:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: awk help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908388#M96803</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;reading your thread again: if you really don't care about the original placement of the quotes, you can use a 'forced' handling of your fields: drop all quotes at input and create new ones at output:&lt;BR /&gt;&lt;BR /&gt;awk -F, -v qu='"' 'NF {gsub(qu,""); printf("%s%s%s",qu,$1,qu)&lt;BR /&gt;for(i=2;i&amp;lt;=NF;i++) printf("%s%s%s%s",FS,qu,$i,qu)&lt;BR /&gt;printf("\n")}' above.csv&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Thu, 07 Dec 2006 03:41:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/3908388#M96803</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-12-07T03:41:04Z</dc:date>
    </item>
  </channel>
</rss>

