Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

grep a number of lines in Solaris

  • 17-04-2007 3:20pm
    #1
    Registered Users, Registered Users 2 Posts: 1,110 ✭✭✭


    Hi all,
    I need to find the line before a line in output on a Solaris box, now with gnu grep I can
    grep -1<pattern> <file>|head -1
    Unfortunately this has to work in other environments so I can't just install GNU grep :(. how would I achieve the same effect on a vanilla Solaris box?


Comments

  • Registered Users, Registered Users 2 Posts: 1,110 ✭✭✭Skrynesaver


    Probably not the most efficient solution, by lots but I found a way to do it
    ...|sed -n '1,/pattern/ p'|tail -2|head -1


  • Registered Users, Registered Users 2 Posts: 2,755 ✭✭✭niallb


    You'll more than likely have perl.
    Wouldn't that give you more options?

    You will have 'ex'.
    I had to use this for some record munging on an archaeological AIX install once.

    Try this:
    ex -s -R -c '/<pattern>/-1|q' <filename>


  • Registered Users, Registered Users 2 Posts: 1,110 ✭✭✭Skrynesaver


    Hi Niall,

    vi proves it's worth again ;)

    While perl is a given on these boxes, I was trying to keep it a shell script, it's sort of grown from a 5 line one off solution to a generic solution (as they do). however it's for parsing and modifying an ldap directory so if I was to use perl I'd have a system(ldapsearch ....) in a loop or I'd have to use Net::LDAP and insist on them installing the module.


Advertisement