+ Reply to Thread
Results 1 to 4 of 4

Thread: Print lines between variables

  1. #1
    Newbie DinoFly is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    2

    Print lines between variables

    Hi

    I am a rookie and I would like to know how to make a script that prints as a output lines between two lines let say first variable is a :


    Mon Aug 31 09:00:00 2009 CET

    and the last line is

    Tue Sep 08 09:00:00 2009 CET

    also

    lets say third line from

    Mon Aug 31 09:00:00 2009 CET




    thanks in advance I would realy apreciate the help

  2. #2
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,680
    Blog Entries
    57

    Re: Print lines between variables

    What do you have so far?
    CodeCall Blog | CodeCall Wiki | Shareware
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  3. #3
    Newbie DinoFly is an unknown quantity at this point
    Join Date
    Jan 2010
    Posts
    2

    Re: Print lines between variables

    For the first part I have a solution which was realy simple:
    a script that prints as a output lines between two lines let say first variable is a :


    Mon Aug 31 09:00:00 2009 CET

    and the last line is

    Tue Sep 08 09:00:00 2009 CET
    and it is :
    awk '/Mon Aug 31 09:00:00 2009 CET/,/Tue Sep 08 09:00:00 2009 CET/' file

    but for the second part printing a specific line after a matched line I am still trying to figure out ...

  4. #4
    Learning Programmer denarced is an unknown quantity at this point
    Join Date
    Jul 2008
    Location
    Joensuu, Finland
    Posts
    91

    Re: Print lines between variables

    If I understand you correctly, you want to print everything between two lines but not the two lines themselves.
    If so, this script ought to do it
    Code:
    #!/bin/bash
    
    if [ $# -lt 1 ]
    then
        exit
    fi
    
    bolle=0
    beginstr="three"
    endstr="seven"
    
    if [ -e $1 ]
    then
        for line in $(cat $1)
        do
            if [ $line == $endstr ]
            then
                bolle=0
            fi
    
            if [ $bolle -eq 1 ]
            then
                echo $line
            fi
    
            if [ $line == $beginstr ]
            then
                bolle=1
            fi
        done
    else
        echo no existo
    fi

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Some Basic Linux Commands, For Beginners...
    By Onur in forum Linux Tutorials, Guides and Tips
    Replies: 5
    Last Post: 10-12-2009, 02:07 AM
  2. Tic-Tac-Toe in Python
    By Vswe in forum Tutorials
    Replies: 6
    Last Post: 10-06-2009, 11:09 AM
  3. Tutorial - Smarterchild copy
    By travy92 in forum VB Tutorials
    Replies: 24
    Last Post: 08-07-2009, 07:50 AM
  4. Please Help
    By Prestidigitator in forum Python
    Replies: 15
    Last Post: 02-28-2009, 08:22 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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