It is currently Tue, 17 May 2022 02:52:58 GMT



 
Author Message
 Display all lines from line which contains some expression
Hi,

I would like to display all lines from specific line till end of file,
from line which contains a word for example "abc".
How can i do it in bash?

Thanks in advance

AG



 Fri, 12 Sep 2008 17:21:25 GMT   
 Display all lines from line which contains some expression
grep "abc"  filename

Regards,

Moody
PTML.



 Fri, 12 Sep 2008 18:04:42 GMT   
 Display all lines from line which contains some expression
grep "abc"  filename

Regards,

Moody
PTML.



 Fri, 12 Sep 2008 18:05:12 GMT   
 Display all lines from line which contains some expression

You can do this.

sed -n -e '/abc/,$p' input.txt

In bash it would be

#! /bin/bash
FOUND=0
while read line
do
   [[ "$line" == *abc* ]] && FOUND=1
   [ $FOUND == 1 ] && echo "$line"
done < input.txt

Vino.



 Fri, 12 Sep 2008 18:39:13 GMT   
 Display all lines from line which contains some expression

awk '/abc/, 0' myfile



 Sat, 13 Sep 2008 00:50:49 GMT   
 Display all lines from line which contains some expression

You appear to be asking for a pure shell solution:

while read -r -- LINE
do
  [[ "${LINE}" == *abc* ]] && echo "${LINE}"
done < yourFile

Additionally, pure shell implementations of fgrep and grep can be found
at:

  http://www.mtxia.com/fancyIndex/Tools/Scripts/Korn/K93_Unix

Dana French
dfre...@mtxia.com



 Sat, 13 Sep 2008 07:02:36 GMT   
 Display all lines from line which contains some expression
Oops,  forgot the IFS setting:

while IFS="" read -r -- LINE
do
  [[ "${LINE}" == *abc* ]] && echo "${LINE}"
done < yourFile

Dana French
dfre...@mtxia.com



 Sat, 13 Sep 2008 07:05:17 GMT   
 Display all lines from line which contains some expression
In article <1143451285.450871.295...@t31g2000cwb.googlegroups.com>,
Everybody, note that what he asks below is *NOT* what you've been answering.
He doesn't want to list only the lines containing the expression ("abc"),
but everything _from_that_line_to_end-of-file_.

There are trivial ways to do this using external utility programs like
'awk' and 'sed'.  However, you appear to be asking for a 'shell command
only' solution.

Here's one way:

        a=false

        while IFS="" read -r -- LINE
        do
          [[ "${LINE}" == *abc* ]] && a=true
          [[ $a == true ]] && echo "${LINE}"
        done < yourFile



 Sat, 13 Sep 2008 08:11:25 GMT   
 Display all lines from line which contains some expression
On 2006-03-28, Robert Bonomi wrote:

   That will be slower than using awk or sed, and it's not portable.
   If you want to use a shell loop you could be portable, and still
   speed it up (though probably not as fast as awk or sed, depending
   on how far into the file the match occurs):

{
   while IFS="" read -r LINE
   do
     case $LINE in
       *abc*) printf "%s\n" "$LINE"
              break ;;
     esac
   done
   cat

--
   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence



 Sat, 13 Sep 2008 13:14:12 GMT   
 Display all lines from line which contains some expression

awk '/abc/ { go = 1 }
     go == 1 { print }'

    If you want it shorter:

awk '/abc/{g=1}g'

--
   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence



 Sat, 13 Sep 2008 13:24:40 GMT   
 Display all lines from line which contains some expression
In article <4atmf3-k1v....@xword.teksavvy.com>,
Chris F.A. Johnson <cfajohn...@gmail.com> wrote:

No shit, sherlock.  <grin>

but he asked 'how can i do it IN BASH', which, _strictly_interpreted_ precludes
using awk or sed.

I didn't suggest that the shell script would be faster.  just that it _was_
a way to do it "according to his requirements'.

'portable' is also moot, when someone *specifies* the 'target environment'. :)

Of course using 'cat' fails a 'pure shell' requirement, too.  :)

aside from that minor matter, I do like your approach.



 Sun, 14 Sep 2008 00:01:29 GMT   
 Display all lines from line which contains some expression
On 2006-03-28, Robert Bonomi wrote:

    If you insist (but see below).

    A portable script also works in the 'target environment'.

    One of the great things about this newsgroup is that solutions are
    frequently given that have a much wider application (whether in
    'target environment' or functionality or whatever) than originally
    requested. This makes the answers useful to many more people than
    just the OP.

- Show quoted text -

$ type cat
cat is a shell builtin

  Thank you.

  That approach can also be used with awk for a faster result than awk
  alone (even with an external cat):

{
   awk '/abc/ { print; exit }'
   cat

--
   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence



 Sun, 14 Sep 2008 00:39:32 GMT   
 Display all lines from line which contains some expression

Wrong, Sherlock.  Note my post.

Are you legally dead?



 Sun, 14 Sep 2008 03:13:27 GMT   
 Display all lines from line which contains some expression
In article <4f5of3-ht9....@xword.teksavvy.com>,
Chris F.A. Johnson <cfajohn...@gmail.com> wrote:

I would *not* want to trust that one.  All it takes is buffered read
(aka read-ahead) on the part of an awk implementation, and there is
an unpredictable amount of 'lost data' in the output.



 Wed, 17 Sep 2008 07:29:29 GMT   
 Display all lines from line which contains some expression
In article <1143573207.948003.16...@z34g2000cwc.googlegroups.com>,

Congratulations!  you did get it right.

However, your article had *NOT* made it to the server I was using at
the time I made my posting.  This happens not infrequently with postings
originating from Google groups.

You are, obviously, in practice, if not 'legally', an assh*le.



 Wed, 17 Sep 2008 07:35:00 GMT   
 
   [ 15 post ] 

Similar Threads

1. Find & print lines containing multiple expressions

2. Displaying images line-by-line

3. Content of file is one line has to be displayed in seperated lines

4. Linux permanent Line (connection two linux machines over a leased line (permanent telephone line)

5. one liner which prints n lines before and m lines after the line found by grep

6. line by line reading of the lines in list

7. Q: sed: How to apply to lines 2,$ containing Y

8. Using awk or the shell to parse a file containing multiple line groups of data


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software