Sponsored Content
Top Forums Shell Programming and Scripting NAWK: changing string-format with split Post 302559548 by regisl67 on Tuesday 27th of September 2011 11:13:57 AM
Old 09-27-2011
Question NAWK: changing string-format with split

Hi all,
I try to make a awk-script, which counts lines, summarized by pdf and xml.
So far it works, but for sorting reasons, I'd like to change the format from the field $1 from dd-mm-yyyy to yyyy-mm-dd.

This works find, but: split() and sprintf() prints its output (for no reason, the results looks like this:

Code:
22-09-2011 09:15:00 Doinggthings 49490388905_49490994.PDF
2011-09-22 09:15:00 Doinggthings 49490388905_49490994.PDF
22-09-2011 09:15:00 Doinggthings 49445688905_49499494.XML
2011-09-22 09:15:00 Doinggthings 49445688905_49499494.XML
23-09-2011 11:20:00 Doinggthings 49490312305_94689494.PDF
2011-09-23 11:20:00 Doinggthings 49490312305_94689494.PDF
23-09-2011 11:20:00 Doinggthings 49490388905_49378494.XML
2011-09-23 11:20:00 Doinggthings 49490388905_49378494.XML
     Datum  Total Files   Total PDFs   Total XMLs
2011-09-22          2          1          1
2011-09-23          2          1          1

Inputfile:
Code:
22-09-2011 09:15:00 Doinggthings 49490388905_49490994.PDF
22-09-2011 09:15:00 Doinggthings 49445688905_49499494.XML
23-09-2011 11:20:00 Doinggthings 49490312305_94689494.PDF
23-09-2011 11:20:00 Doinggthings 49490388905_49378494.XML

My actual script:
Code:
#!/usr/bin/nawk -f

BEGIN {
        FS=" "
        IGNORECASE = 1 }

split($1, d, "-")
$1 = sprintf("%s-%s-%s", d[3],d[2],d[1])

$1 != "" && $NF ~ /\.PDF/ {a[$1]++;b[$1]++}
$1 != "" && $NF ~ /\.XML/ {a[$1]++;c[$1]++}

END {
        printf("%10s %12s %12s %12s\n", "Datum", "Total Files", "Total PDFs", "Total XMLs" )
        for (i in a)
                printf("%s %10.0f %10.0f %10.0f\n", i, a[i], b[i], c[i] )}
                #printf("%s %10.0f %10.0f %10.0f\n", i, a[i,t], b[i,p], c[i,x] )}

I have to use nawk instead of awk, because awk dosn't support split().
I run this on Solaris 10.
Does nawk behave differently?

Has anybody a good idea?

Thanks a lot.
Regis

Last edited by pludi; 09-27-2011 at 07:11 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Nawk Split

Hello. I have a input file in this format: line1data :: line1data :: line1data line2data :: line2data :: line2data I would like to split each lines data element into an array: array1=line1data array1=line1data array1=line1data array2=line2data array2=line2data array2=line2data I... (3 Replies)
Discussion started by: steveramsey
3 Replies

2. UNIX for Dummies Questions & Answers

Split BIG report using nawk

I have the following nawk script: nawk -F: '{ if($0 ~ "^Report No") {fl=1; i=0;} if(fl==1){data=$0; i++} if($0 ~ "^BE NO:") { fname = "reprot_"$2".lis"; gsub(" ","",fname); for(j=0;j<i;j++) print data > fname; fl=0; } else if(fl==0) print $0 > fname; }' filename When I try to apply... (1 Reply)
Discussion started by: raychu65
1 Replies

3. Shell Programming and Scripting

changing month in Mmm format to mm FORMAT

i have an variable mydate=2008Nov07 i want o/p as in variable mymonth=11 (i.e nov comes on 11 number month) i want some command to do this for any month without using any loop. plz help me (1 Reply)
Discussion started by: RahulJoshi
1 Replies

4. Shell Programming and Scripting

awk/nawk question to format a file

Hi, I am new to awk/nawk, needs help. I want to merge the rows having emplid attribute same into a single row in the following file. In actual this kind of file will have around 50k rows. Here is my input file id|emplid|firstname|dep|lastname 1|001234|test|1001|1 2|002345|test|1032|2... (7 Replies)
Discussion started by: kumar04
7 Replies

5. Shell Programming and Scripting

Format - Inventory Row data into Column - Awk - Nawk

Hi All, I have the following file that has computer data for various pcs in my network... Snap of the file is as follows ******************************************************************************* Serial 123456 Computer IP Address lo0:... (1 Reply)
Discussion started by: aavam
1 Replies

6. UNIX for Dummies Questions & Answers

Changing from Excel date format to MySQL date format

I have a list of dates in the following format: mm/dd/yyyy and want to change these to the MySQL standard format: yyyy-mm-dd. The dates in the original file may or may not be zero padded, so April is sometimes "04" and other times simply "4". This is what I use to change the format: sed -i '' -e... (2 Replies)
Discussion started by: figaro
2 Replies

7. Shell Programming and Scripting

how to parse the file in xml format using awk/nawk

Hi All, I have an xml file with the below format. <a>111</a><b>222</b><c>333<c><d><e>123</e><f>234</f><d><e>456</e><f>789</f> output needed is 111,222,333,123,234 111,222,333,456,789 nawk 'BEGIN{FS="<|>"} {print a,b,c,e,f a="" ... (7 Replies)
Discussion started by: natalie23
7 Replies

8. Shell Programming and Scripting

Nawk Format

Hi! I have a file which I want to search daily for any line that contains the work 'Reason' and I want to take that line and put the data in a certain format using awk or nawk....I do not have gawk on my machine so it would have to be awk or nawk, or sed would work as well. Here are some examples... (9 Replies)
Discussion started by: ther2000
9 Replies

9. Shell Programming and Scripting

Using awk or nawk to convert epoch time to date format

Looking for some help and usually when I do a search this site comes up. Hopefully someone can give me a little direction as to how to use one of these two commands to achieve what I'm trying to do. What am I trying to do? I need to take the time value in epoch format returned from the... (5 Replies)
Discussion started by: minigts
5 Replies

10. UNIX for Beginners Questions & Answers

Date format conversion how to change this from using nawk to awk

Hi, I have a file where I need to change the date format on the nth field from DD-MM-YYYY to YYYY-MM-DD so I can accurately sort the record by dates From regex - Use sed or awk to fix date format - Stack Overflow, I found an example using nawk. Test run as below: $: cat xyz.txt A ... (2 Replies)
Discussion started by: newbie_01
2 Replies
pdfseparate(1)						      General Commands Manual						    pdfseparate(1)

NAME
pdfseparate - Portable Document Format (PDF) page extractor SYNOPSIS
pdfseparate [options] PDF-file PDF-page-pattern DESCRIPTION
pdfseparate extract single pages from a Portable Document Format (PDF). pdfseparate reads the PDF file PDF-file, extracts one or more pages, and writes one PDF file for each page to PDF-page-pattern, PDF-page- pattern should contain %d. %d is replaced by the page number. The PDF-file should not be encrypted. OPTIONS
-f number Specifies the first page to extract. If -f is omitted, extraction starts with page 1. -l number Specifies the last page to extract. If -l is omitted, extraction ends with the last page. -v Print copyright and version information. -h Print usage information. (-help and --help are equivalent.) EXAMPLE
pdfseparate sample.pdf sample-%d.pdf extracts all pages from sample.pdf, if i.e. sample.pdf has 3 pages, it produces sample-1.pdf, sample-2.pdf, sample-3.pdf AUTHOR
The pdfseparate software and documentation are copyright 1996-2004 Glyph & Cog, LLC and copyright 2005-2011 The Poppler Developers - http://poppler.freedesktop.org SEE ALSO
pdfunite(1), 15 September 2011 pdfseparate(1)
All times are GMT -4. The time now is 03:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy