LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-30-2015, 03:08 PM   #1
Zacariaz
LQ Newbie
 
Registered: Jun 2011
Posts: 28

Rep: Reputation: Disabled
Multiple passes with AWK or perhaps alternatives


I'm posting here as I don't know where else to put it.

I have a couple of AWK scripts looking like so:

date.awk
Code:
BEGIN {
    FS = ","
    datetime = strftime( "Ym%d", systime() );
}

{
    printf " %s %s %s %s %s %s %s %s %s %s\n",
        $( substr( datetime, 1, 1 ) + 1 ), \
        $( substr( datetime, 2, 1 ) + 1 ), \
        $( substr( datetime, 3, 1 ) + 1 ), \
        $( substr( datetime, 4, 1 ) + 1 ), \
        $11, \
        $( substr( datetime, 5, 1 ) + 1 ), \
        $( substr( datetime, 6, 1 ) + 1 ), \
        $11, \
        $( substr( datetime, 7, 1 ) + 1 ), \
        $( substr( datetime, 8, 1 ) + 1 )
}

END {
    printf "      .\n"
}
time.awk
Code:
BEGIN {
    FS = ","
    datetime = strftime( "%H%M%S", systime() );
}

{
    switch (NR) {
        case 1:
            printf "     / \\     "
            break
        case 2:
            printf "    /'. \\    "
            break
        case 3:
            printf "   / .-. \\   "
            break
        case 4:
            printf "  / (   )'\\  "
            break
        case 5:
            printf " /.'     '.\\ "
            break
    default:
        break
    }
    printf "%s %s %s %s %s %s %s %s\n",
        $( substr( datetime, 1, 1 ) + 1 ), \
        $( substr( datetime, 2, 1 ) + 1 ), \
        $12, \
        $( substr( datetime, 3, 1 ) + 1 ), \
        $( substr( datetime, 4, 1 ) + 1 ), \
        $12, \
        $( substr( datetime, 5, 1 ) + 1 ), \
        $( substr( datetime, 6, 1 ) + 1 )
}

END {
    printf "\n"
}
7sd.csv (data)
Code:
#####,    #,#####,#####,#   #,#####,#    ,#####,#####,#####,    #,     ,
#   #,    #,    #,    #,#   #,#    ,#    ,    #,#   #,#   #,   # ,  #  ,
#   #,    #,#####,#####,#####,#####,#####,    #,#####,#####,  #  ,     ,
#   #,    #,#    ,    #,    #,    #,#   #,    #,#   #,    #, #   ,  #  ,
#####,    #,#####,#####,    #,#####,#####,    #,#####,    #,#    ,     ,
When run in the right order, it will output date and time in large friendly letter, including a small fancy Arch Linux logo.

Everything works exactly as it should.

I'm always for optimizing, and since this is supposed to run once every second as is, and even on a somewhat slow platform, perhaps that's not a bad thing.

I would like to combine the two scripts, and I find it difficult to understand why you can't simple do multiple passes in one, without playing around with loops and such. Insights on this topic would be welcome.

I have also wondered if this sort of script can actually be compiled, but have yet to find satisfactory answers.

Lastly, I originally tried to implement this in pure bash, but frankly I hadn't a clue where to start, so alternative approaches would be welcome also.


In the end, what I've got actually works, so I'm not too concerned, but I like to learn new stuff, so please feel free to enlighten me if you so desire.


Best regards.

Last edited by Zacariaz; 06-30-2015 at 03:09 PM.
 
Old 07-01-2015, 07:18 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,511

Rep: Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434
what about:
Code:
banner $(date +%Y%m%d)
 
Old 07-01-2015, 04:10 PM   #3
Zacariaz
LQ Newbie
 
Registered: Jun 2011
Posts: 28

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
what about:
Code:
banner $(date +%Y%m%d)
Didn't know that one, but no, doesn't look right to me.
 
Old 07-02-2015, 01:51 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,511

Rep: Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434Reputation: 2434
and what is the problem with it?
 
Old 07-02-2015, 05:16 PM   #5
Zacariaz
LQ Newbie
 
Registered: Jun 2011
Posts: 28

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
and what is the problem with it?
Don't look right. Perhaps there's a way to make it look right, but if so, I don't know how.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] AWK: how to process data multiple times in awk pix9 Programming 11 04-24-2014 08:31 AM
[SOLVED] Replacing multiple string in multiple files with awk jnorbert Linux - Newbie 9 03-26-2013 01:39 PM
Does multiple passes when shredding free space/files actually help? Cultist Linux - Security 6 12-08-2011 09:17 AM
[SOLVED] AWK Multiple Passes MTK358 Programming 14 03-13-2010 02:03 AM
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 06:08 PM


All times are GMT -5. The time now is 01:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration