Skip to main content
Removed occurences tag as per http://meta.stackoverflow.com/questions/169960/rename-the-occurences-tag
Source Link
iDev
  • 23.3k
  • 7
  • 63
  • 86

I'mI am working in a bash shell and I am trying to print only the line of the first occurrence of the string. For example, for the string 'auir', if I have the file myfile.txt and it contains:

123 asdf 4wirajw forauir somethingelse starcraft mylifeforauir auir something else tf.rzauir 

I want to output "forauir somethingelse"

So far, I use the command

sed -n '/auir/p' myfile.txt 

which gives me all the occurrences of this string. How can I only get the first line that 'auir' occurs on? It'd be great if it was just a single command or pipeline of commands.

Any insight is greatly appreciated.

I'm working in a bash shell and I am trying to print only the line of the first occurrence of the string. For example, for the string 'auir', if I have the file myfile.txt and it contains:

123 asdf 4wirajw forauir somethingelse starcraft mylifeforauir auir something else tf.rzauir 

I want to output "forauir somethingelse"

So far, I use the command

sed -n '/auir/p' myfile.txt 

which gives me all the occurrences of this string. How can I only get the first line that 'auir' occurs on? It'd be great if it was just a single command or pipeline of commands.

Any insight is greatly appreciated.

I am working in a bash shell and I am trying to print only the line of the first occurrence of the string. For example, for the string 'auir', if I have the file myfile.txt and it contains:

123 asdf 4wirajw forauir somethingelse starcraft mylifeforauir auir something else tf.rzauir 

I want to output "forauir somethingelse"

So far, I use the command

sed -n '/auir/p' myfile.txt 

which gives me all the occurrences of this string. How can I only get the first line that 'auir' occurs on? It'd be great if it was just a single command or pipeline of commands.

Any insight is greatly appreciated.

I'm working in a bash shell and I am trying to print only the line of the first occurrence of the string. For example, for the string 'auir''auir', if I have the file myfile.txt and it contains:

123 asdf 4wirajw forauir somethingelse starcraft mylifeforauir auir something else tf.rzauir

123 asdf 4wirajw forauir somethingelse starcraft mylifeforauir auir something else tf.rzauir 

I want to output "forauir somethingelse""forauir somethingelse"

So far, I use the command

sed -n '/auir/p' myfile.txt

sed -n '/auir/p' myfile.txt 

which gives me all the occurrences of this string. How can I only get the first line that 'auir''auir' occurs on? It'd be great if it was just a single command or pipeline of commands.

Any insight is greatly appreciated.

I'm working in a bash shell and I am trying to print only the line of the first occurrence of the string. For example, for the string 'auir', if I have the file myfile.txt and it contains:

123 asdf 4wirajw forauir somethingelse starcraft mylifeforauir auir something else tf.rzauir

I want to output "forauir somethingelse"

So far, I use the command

sed -n '/auir/p' myfile.txt

which gives me all the occurrences of this string. How can I only get the first line that 'auir' occurs on? It'd be great if it was just a single command or pipeline of commands.

Any insight is greatly appreciated.

I'm working in a bash shell and I am trying to print only the line of the first occurrence of the string. For example, for the string 'auir', if I have the file myfile.txt and it contains:

123 asdf 4wirajw forauir somethingelse starcraft mylifeforauir auir something else tf.rzauir 

I want to output "forauir somethingelse"

So far, I use the command

sed -n '/auir/p' myfile.txt 

which gives me all the occurrences of this string. How can I only get the first line that 'auir' occurs on? It'd be great if it was just a single command or pipeline of commands.

Any insight is greatly appreciated.

Source Link
Rickster
  • 1.4k
  • 6
  • 19
  • 47

UNIX: Using egrep or sed to find the line with the first occurrence of a string?

I'm working in a bash shell and I am trying to print only the line of the first occurrence of the string. For example, for the string 'auir', if I have the file myfile.txt and it contains:

123 asdf 4wirajw forauir somethingelse starcraft mylifeforauir auir something else tf.rzauir

I want to output "forauir somethingelse"

So far, I use the command

sed -n '/auir/p' myfile.txt

which gives me all the occurrences of this string. How can I only get the first line that 'auir' occurs on? It'd be great if it was just a single command or pipeline of commands.

Any insight is greatly appreciated.