Closed Thread
Results 1 to 4 of 4

Thread: Print lines between variables

  1. #1
    DinoFly is offline Newbie
    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0

    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. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Print lines between variables

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

  4. #3
    DinoFly is offline Newbie
    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0

    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 ...

  5. #4
    denarced is offline Programmer
    Join Date
    Jul 2008
    Location
    Joensuu, Finland
    Posts
    182
    Rep Power
    0

    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

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. for loop to print even numbers in lines
    By Guna Raj Kuikel in forum JavaScript and CSS
    Replies: 2
    Last Post: 09-26-2011, 07:08 AM
  2. Replies: 5
    Last Post: 08-15-2011, 05:32 AM
  3. How do I erase lines in C#?
    By qu20 in forum C# Programming
    Replies: 4
    Last Post: 05-10-2010, 03:21 AM
  4. Ten Lines or Less!
    By ZekeDragon in forum Games
    Replies: 26
    Last Post: 08-30-2009, 05:06 PM
  5. Intercept of two lines
    By ejbennett in forum C and C++
    Replies: 3
    Last Post: 01-18-2009, 05:26 AM

Tags for this Thread

Bookmarks

Posting Permissions

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