select a certain line from file

This is a discussion on select a certain line from file within the Linux Programming forums, part of the Platform Specific Boards category; hi again! I'm writing a bash script and I wonder how can I select a certain line from a file.For ...

  1. #1
    quo
    quo is offline
    Registered User
    Join Date
    May 2011
    Posts
    116

    select a certain line from file

    hi again!

    I'm writing a bash script and I wonder how can I select a certain line from a file.For example I only want the line that starts with
    a specific word(given that there's only one starting with this word)
    and then by using sed perform an operation to this certain line

    Code:
    Residence: info info2 info2
    So I want the line that starts with Residence: and then do something with sed to this line

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Given that sed will find the line for you as well, what's the point of using something else?

    sed '/pattern/x' file

    pattern is what you want to look for
    x is what you want to do
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 12-13-2010, 01:13 PM
  2. A fifo file and select() problem
    By itsdafoetime in forum C Programming
    Replies: 2
    Last Post: 03-08-2009, 01:23 AM
  3. file select row
    By De_Lėtzeboier in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2008, 12:44 PM
  4. file select
    By EllieProgrammer in forum C Programming
    Replies: 6
    Last Post: 04-11-2005, 11:00 AM
  5. Select: Bad File Number
    By _Cl0wn_ in forum C++ Programming
    Replies: 2
    Last Post: 05-08-2003, 09:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21