Find the answer to your Linux question:
Results 1 to 10 of 10
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Entry Handling with AWK


    Hello everyone,

    I have an awk script that turns a text document with tabbed separated values into an "XML" document (without the xml headers) most of the text documents that get processed are just numbers in the format of ##.# or ### but every once in a while, they might have an entry that is text like "status change channel (#): Tower Lights on." I am not sure how to handle this. the AWK script that I have is attached. Any help would be appreciated.
    Attached Files Attached Files

  2. #2
    hi,

    can't read attached file.
    it doesn't seem so heavy you can't post content here.

  3. #3
    BEGIN { FS=" "; } # Put in the real TAB character here
    NR==1 { split ($0,header,FS);
    printf "<log>\n"}
    NR >1 {
    printf "<entry>\n";
    for(i=1;i<=NF;i++)
    printf " <%s>%s</%s>\n", header[i],$i,header[i];
    printf "</entry>\n";}

    END { printf "</log>\n" }

  4. $spacer_open
    $spacer_close
  5. #4
    it is a real basic script that takes the tab separated values at the first line of the page and turns them into tags. Would a sample raw text document help?

  6. #5
    yes, a little sample would be nice, thank you.

    you could test wether $i+0 equals $i
    if it does then $i is a number.

  7. #6
    I have attached the end outcome. What I'm shooting for is to take the entries that have text instead of values and try to put some tags around them to format and handle them better. The text document is the raw data and the PDF is what I convert the information to.
    Attached Files Attached Files

  8. #7
    no way !
    I can't access attached files.

  9. #8
    what error are you getting when trying to open the files?

  10. #9
    The text below is a sample of the raw data. I'm not sure why you are not able to see what I attach.


    "Timestamp" " ()" " ()" " ()" " ()" " ()" " ()"
    "3/31/2017 12:00:00 AM" 101.69 101.76 2.76 61.95 100.24 110 87.44 188 0 24.94
    "3/31/2017 4:00:00 AM" 101.83 101.76 2.75 60.36 99.37 110.08 24.43 187 0 103.52
    "3/31/2017 5:41:13 AM" "Priority 0 Warning Low Limit Alarm on AM Forward Power (Ch 1)"
    "3/31/2017 5:41:13 AM" "Priority 0 Warning Low Limit Alarm on AM Forward Power (Ch 1)"
    "3/31/2017 5:39:40 AM" 102.18 102.18 2.78 61.04 100.64 110 110.05 187 0 98.53
    "3/31/2017 7:18:26 AM" "Priority 0 Critical Low Limit Alarm on AM Audio Level (Ch 7)"
    "3/31/2017 7:18:26 AM" "Priority 0 Critical Low Limit Alarm on AM Audio Level (Ch 7)"
    "3/31/2017 7:16:53 AM" 101.97 101.9 2.77 60.59 99.84 110 66.44 188 0 86.06
    "3/31/2017 8:00:00 AM" 101.83 101.97 2.78 61.04 99.37 109.92 114.16 187 0 59.87
    "3/31/2017 12:00:01 PM" 101.83 101.97 2.76 61.04 99.64 110.23 212.56 189 0 3.74
    "3/31/2017 12:00:20 PM" "Status change (Ch 1): BEACON 1 OK"
    "3/31/2017 12:00:20 PM" "Status change (Ch 2): BEACON 2 OK"
    "3/31/2017 12:12:33 PM" "Status change (Ch 1): BEACON 1 OFF"
    "3/31/2017 12:12:33 PM" "Status change (Ch 2): BEACON 2 OFF"
    "3/31/2017 12:15:28 PM" "Priority 0 Critical Status Alarm : BEACON 1 OFF (Ch 1)"
    "3/31/2017 12:15:28 PM" "Priority 0 Critical Status Alarm : BEACON 1 OFF (Ch 1)"
    "3/31/2017 12:15:28 PM" "Priority 0 Critical Status Alarm : BEACON 2 OFF (Ch 2)"
    "3/31/2017 12:15:28 PM" "Priority 0 Critical Status Alarm : BEACON 2 OFF (Ch 2)"
    "3/31/2017 12:13:22 PM" "Status change (Ch 1): BEACON 1 OK"
    "3/31/2017 12:13:22 PM" "Status change (Ch 2): BEACON 2 OK"
    "3/31/2017 12:13:53 PM" 101.9 101.9 2.76 61.27 99.77 110 52.28 187 0 51.13
    "3/31/2017 4:00:00 PM" 101.27 101.48 2.77 61.5 101.37 110 13.7 187 0 113.49
    "3/31/2017 6:19:45 PM" "Status change (Ch 1): BEACON 1 OFF"
    "3/31/2017 6:22:41 PM" "Priority 0 Critical Status Alarm : BEACON 1 OFF (Ch 1)"
    "3/31/2017 6:22:41 PM" "Priority 0 Critical Status Alarm : BEACON 1 OFF (Ch 1)"
    "3/31/2017 6:21:07 PM" 101.41 101.55 2.76 60.14 96.83 109.92 85.84 187 0 56.12
    "3/31/2017 8:00:00 PM" 102.04 101.83 2.78 60.82 96.69 109.85 13.24 184 0 295.58

  11. #10
    firefox complains about page not being correctly redirected.

    I'm not sure I understand what you want to do :
    Code:
    $ awk 'BEGIN { FS="\t"; } # Put in the real TAB character here
    NR==1 { split ($0,header,FS);
    printf "<log>\n"}
    NR >1 {
    printf "<entry>\n";
    for(i=1;i<=NF;i++){if(i==1)printf " <%s>%s</%s>\n", header[i],$i,header[i];else if($i+0==$i)printf " <%s>%s</%s>\n", header[i],$i,header[i];else printf " <textTag>%s</textTag>\n",$i}
    printf "</entry>\n";}
    
    END { printf "</log>\n" } ' Ethaniz3d.lf.in
    <log>
    <entry>
     <"Timestamp">"3/31/2017 12:00:00 AM"</"Timestamp">
     <" ()">101.69</" ()">
     <" ()">101.76</" ()">
     <" ()">2.76</" ()">
     <" ()">61.95</" ()">
     <" ()">100.24</" ()">
     <" ()">110</" ()">
     <>87.44</>
     <>188</>
     <>0</>
     <>24.94</>
    </entry>
    <entry>
     <"Timestamp">"3/31/2017 4:00:00 AM"</"Timestamp">
     <" ()">101.83</" ()">
     <" ()">101.76</" ()">
     <" ()">2.75</" ()">
     <" ()">60.36</" ()">
     <" ()">99.37</" ()">
     <" ()">110.08</" ()">
     <>24.43</>
     <>187</>
     <>0</>
     <>103.52</>
    </entry>
    <entry>
     <"Timestamp">"3/31/2017 5:41:13 AM"</"Timestamp">
     <textTag>"Priority 0 Warning Low Limit Alarm on AM Forward Power (Ch 1)"</textTag>
    </entry>
    <entry>
     <"Timestamp">"3/31/2017 5:41:13 AM"</"Timestamp">
     <textTag>"Priority 0 Warning Low Limit Alarm on AM Forward Power (Ch 1)"</textTag>
    </entry>
    <entry>
     <"Timestamp">"3/31/2017 5:39:40 AM"</"Timestamp">
     <" ()">102.18</" ()">
     <" ()">102.18</" ()">
     <" ()">2.78</" ()">
     <" ()">61.04</" ()">
     <" ()">100.64</" ()">
     <" ()">110</" ()">
     <>110.05</>
     <>187</>
     <>0</>
     <>98.53</>
    </entry>
    </log>
    if it's not what you want, please paste the corresponding output for the sixth first lines.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •