How to print the line from a file that contains the matching characters in the pattern
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am trying to print all the lines from a file that has the same characters of the matching pattern.
Here is my pattern -
CurrentPrincipal[MRC]
CurrentPrincipalLegalEventAssociation
In the file I have the lines like the below ones
823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition
I am iterating my pattern and printing its matching lines from the file. What I need is, when I iterate my pattern CurrentPrincipal[MRC]
I should get only its matching line
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
and when the pattern is CurrentPrincipalLegalEventAssociation
I should get only
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
My requirement is to ignore the [
]
from the line while matching pattern.
I have tried my best to put my issue affront. Do let me know if anything else is needed from me.
Thanks in advance.
text-processing
add a comment |Â
up vote
1
down vote
favorite
I am trying to print all the lines from a file that has the same characters of the matching pattern.
Here is my pattern -
CurrentPrincipal[MRC]
CurrentPrincipalLegalEventAssociation
In the file I have the lines like the below ones
823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition
I am iterating my pattern and printing its matching lines from the file. What I need is, when I iterate my pattern CurrentPrincipal[MRC]
I should get only its matching line
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
and when the pattern is CurrentPrincipalLegalEventAssociation
I should get only
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
My requirement is to ignore the [
]
from the line while matching pattern.
I have tried my best to put my issue affront. Do let me know if anything else is needed from me.
Thanks in advance.
text-processing
1
I'm sorry but I don't understand what you need. Please edit your question and show us an example of your input file, including both desired and undesired lines, and then show us the output you would expect from that example.
â terdonâ¦
Jan 5 at 12:16
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am trying to print all the lines from a file that has the same characters of the matching pattern.
Here is my pattern -
CurrentPrincipal[MRC]
CurrentPrincipalLegalEventAssociation
In the file I have the lines like the below ones
823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition
I am iterating my pattern and printing its matching lines from the file. What I need is, when I iterate my pattern CurrentPrincipal[MRC]
I should get only its matching line
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
and when the pattern is CurrentPrincipalLegalEventAssociation
I should get only
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
My requirement is to ignore the [
]
from the line while matching pattern.
I have tried my best to put my issue affront. Do let me know if anything else is needed from me.
Thanks in advance.
text-processing
I am trying to print all the lines from a file that has the same characters of the matching pattern.
Here is my pattern -
CurrentPrincipal[MRC]
CurrentPrincipalLegalEventAssociation
In the file I have the lines like the below ones
823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition
I am iterating my pattern and printing its matching lines from the file. What I need is, when I iterate my pattern CurrentPrincipal[MRC]
I should get only its matching line
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
and when the pattern is CurrentPrincipalLegalEventAssociation
I should get only
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
My requirement is to ignore the [
]
from the line while matching pattern.
I have tried my best to put my issue affront. Do let me know if anything else is needed from me.
Thanks in advance.
text-processing
asked Jan 4 at 14:06
Alex Raj Kaliamoorthy
192111
192111
1
I'm sorry but I don't understand what you need. Please edit your question and show us an example of your input file, including both desired and undesired lines, and then show us the output you would expect from that example.
â terdonâ¦
Jan 5 at 12:16
add a comment |Â
1
I'm sorry but I don't understand what you need. Please edit your question and show us an example of your input file, including both desired and undesired lines, and then show us the output you would expect from that example.
â terdonâ¦
Jan 5 at 12:16
1
1
I'm sorry but I don't understand what you need. Please edit your question and show us an example of your input file, including both desired and undesired lines, and then show us the output you would expect from that example.
â terdonâ¦
Jan 5 at 12:16
I'm sorry but I don't understand what you need. Please edit your question and show us an example of your input file, including both desired and undesired lines, and then show us the output you would expect from that example.
â terdonâ¦
Jan 5 at 12:16
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
You appear to want the [
and ]
characters to be treated literally rather than as indicating a character range. You can do that by escaping them:
grep 'CurrentPrincipal[LegalEventAssociation]' file
Ex. given:
$ cat file
823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition
then
$ grep 'CurrentPrincipal[LegalEventAssociation]' file
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
Alternatively use the -F
or --fixed-strings
option to tell grep to treat all characters literally:
$ grep -F 'CurrentPrincipal[LegalEventAssociation]' file
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
This is fine but my search pattern isCurrentPrincipalLegalEventAssociation
and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the linec755ad,atom.list,CurrentPrincipal[LegalEventAssociation][TypâÂÂâÂÂe][*],CompanyElementâÂÂ
when the search pattern isCurrentPrincipalLegalEventAssociation
. While searching the file with this pattern I should tell the command to ignore the brackets of that line.
â Alex Raj Kaliamoorthy
Jan 4 at 14:19
1
@AlexRajKaliamoorthy please see my updated answer usinggrep -F
. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower casef
) to read patterns directly from a file.
â steeldriver
Jan 4 at 14:27
Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is justCurrentPrincipalLegalEventAssociation
â Alex Raj Kaliamoorthy
Jan 4 at 14:35
1
@AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
â Jesse_b
Jan 4 at 15:10
1
Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
â Jesse_b
Jan 4 at 15:16
 |Â
show 3 more comments
up vote
1
down vote
grep seems to do what you want.
grep 'word' filename
Will print every line in the file 'filename' that contains 'word'.
I have tried this already but if you see, my file has1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
and I need onlyc755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
. The line I need contains brackets and I want to ignore that while searching.
â Alex Raj Kaliamoorthy
Jan 4 at 14:13
add a comment |Â
up vote
0
down vote
Using the following, the file output appears in next line in the file after pattern search line.
sed -n '/CurrentPrincipal[MRC]/p' filename | sed -n '2p'
Output
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
sed -n '/CurrentPrincipalLegalEventAssociation/,+1p' l.txt | sed -n '2p'
Output
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
You appear to want the [
and ]
characters to be treated literally rather than as indicating a character range. You can do that by escaping them:
grep 'CurrentPrincipal[LegalEventAssociation]' file
Ex. given:
$ cat file
823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition
then
$ grep 'CurrentPrincipal[LegalEventAssociation]' file
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
Alternatively use the -F
or --fixed-strings
option to tell grep to treat all characters literally:
$ grep -F 'CurrentPrincipal[LegalEventAssociation]' file
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
This is fine but my search pattern isCurrentPrincipalLegalEventAssociation
and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the linec755ad,atom.list,CurrentPrincipal[LegalEventAssociation][TypâÂÂâÂÂe][*],CompanyElementâÂÂ
when the search pattern isCurrentPrincipalLegalEventAssociation
. While searching the file with this pattern I should tell the command to ignore the brackets of that line.
â Alex Raj Kaliamoorthy
Jan 4 at 14:19
1
@AlexRajKaliamoorthy please see my updated answer usinggrep -F
. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower casef
) to read patterns directly from a file.
â steeldriver
Jan 4 at 14:27
Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is justCurrentPrincipalLegalEventAssociation
â Alex Raj Kaliamoorthy
Jan 4 at 14:35
1
@AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
â Jesse_b
Jan 4 at 15:10
1
Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
â Jesse_b
Jan 4 at 15:16
 |Â
show 3 more comments
up vote
2
down vote
You appear to want the [
and ]
characters to be treated literally rather than as indicating a character range. You can do that by escaping them:
grep 'CurrentPrincipal[LegalEventAssociation]' file
Ex. given:
$ cat file
823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition
then
$ grep 'CurrentPrincipal[LegalEventAssociation]' file
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
Alternatively use the -F
or --fixed-strings
option to tell grep to treat all characters literally:
$ grep -F 'CurrentPrincipal[LegalEventAssociation]' file
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
This is fine but my search pattern isCurrentPrincipalLegalEventAssociation
and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the linec755ad,atom.list,CurrentPrincipal[LegalEventAssociation][TypâÂÂâÂÂe][*],CompanyElementâÂÂ
when the search pattern isCurrentPrincipalLegalEventAssociation
. While searching the file with this pattern I should tell the command to ignore the brackets of that line.
â Alex Raj Kaliamoorthy
Jan 4 at 14:19
1
@AlexRajKaliamoorthy please see my updated answer usinggrep -F
. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower casef
) to read patterns directly from a file.
â steeldriver
Jan 4 at 14:27
Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is justCurrentPrincipalLegalEventAssociation
â Alex Raj Kaliamoorthy
Jan 4 at 14:35
1
@AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
â Jesse_b
Jan 4 at 15:10
1
Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
â Jesse_b
Jan 4 at 15:16
 |Â
show 3 more comments
up vote
2
down vote
up vote
2
down vote
You appear to want the [
and ]
characters to be treated literally rather than as indicating a character range. You can do that by escaping them:
grep 'CurrentPrincipal[LegalEventAssociation]' file
Ex. given:
$ cat file
823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition
then
$ grep 'CurrentPrincipal[LegalEventAssociation]' file
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
Alternatively use the -F
or --fixed-strings
option to tell grep to treat all characters literally:
$ grep -F 'CurrentPrincipal[LegalEventAssociation]' file
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
You appear to want the [
and ]
characters to be treated literally rather than as indicating a character range. You can do that by escaping them:
grep 'CurrentPrincipal[LegalEventAssociation]' file
Ex. given:
$ cat file
823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition
then
$ grep 'CurrentPrincipal[LegalEventAssociation]' file
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
Alternatively use the -F
or --fixed-strings
option to tell grep to treat all characters literally:
$ grep -F 'CurrentPrincipal[LegalEventAssociation]' file
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
edited Jan 4 at 14:26
answered Jan 4 at 14:15
steeldriver
31.6k34979
31.6k34979
This is fine but my search pattern isCurrentPrincipalLegalEventAssociation
and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the linec755ad,atom.list,CurrentPrincipal[LegalEventAssociation][TypâÂÂâÂÂe][*],CompanyElementâÂÂ
when the search pattern isCurrentPrincipalLegalEventAssociation
. While searching the file with this pattern I should tell the command to ignore the brackets of that line.
â Alex Raj Kaliamoorthy
Jan 4 at 14:19
1
@AlexRajKaliamoorthy please see my updated answer usinggrep -F
. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower casef
) to read patterns directly from a file.
â steeldriver
Jan 4 at 14:27
Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is justCurrentPrincipalLegalEventAssociation
â Alex Raj Kaliamoorthy
Jan 4 at 14:35
1
@AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
â Jesse_b
Jan 4 at 15:10
1
Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
â Jesse_b
Jan 4 at 15:16
 |Â
show 3 more comments
This is fine but my search pattern isCurrentPrincipalLegalEventAssociation
and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the linec755ad,atom.list,CurrentPrincipal[LegalEventAssociation][TypâÂÂâÂÂe][*],CompanyElementâÂÂ
when the search pattern isCurrentPrincipalLegalEventAssociation
. While searching the file with this pattern I should tell the command to ignore the brackets of that line.
â Alex Raj Kaliamoorthy
Jan 4 at 14:19
1
@AlexRajKaliamoorthy please see my updated answer usinggrep -F
. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower casef
) to read patterns directly from a file.
â steeldriver
Jan 4 at 14:27
Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is justCurrentPrincipalLegalEventAssociation
â Alex Raj Kaliamoorthy
Jan 4 at 14:35
1
@AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
â Jesse_b
Jan 4 at 15:10
1
Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
â Jesse_b
Jan 4 at 15:16
This is fine but my search pattern is
CurrentPrincipalLegalEventAssociation
and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the line c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][TypâÂÂâÂÂe][*],CompanyElementâÂÂ
when the search pattern is CurrentPrincipalLegalEventAssociation
. While searching the file with this pattern I should tell the command to ignore the brackets of that line.â Alex Raj Kaliamoorthy
Jan 4 at 14:19
This is fine but my search pattern is
CurrentPrincipalLegalEventAssociation
and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the line c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][TypâÂÂâÂÂe][*],CompanyElementâÂÂ
when the search pattern is CurrentPrincipalLegalEventAssociation
. While searching the file with this pattern I should tell the command to ignore the brackets of that line.â Alex Raj Kaliamoorthy
Jan 4 at 14:19
1
1
@AlexRajKaliamoorthy please see my updated answer using
grep -F
. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower case f
) to read patterns directly from a file.â steeldriver
Jan 4 at 14:27
@AlexRajKaliamoorthy please see my updated answer using
grep -F
. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower case f
) to read patterns directly from a file.â steeldriver
Jan 4 at 14:27
Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is just
CurrentPrincipalLegalEventAssociation
â Alex Raj Kaliamoorthy
Jan 4 at 14:35
Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is just
CurrentPrincipalLegalEventAssociation
â Alex Raj Kaliamoorthy
Jan 4 at 14:35
1
1
@AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
â Jesse_b
Jan 4 at 15:10
@AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
â Jesse_b
Jan 4 at 15:10
1
1
Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
â Jesse_b
Jan 4 at 15:16
Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
â Jesse_b
Jan 4 at 15:16
 |Â
show 3 more comments
up vote
1
down vote
grep seems to do what you want.
grep 'word' filename
Will print every line in the file 'filename' that contains 'word'.
I have tried this already but if you see, my file has1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
and I need onlyc755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
. The line I need contains brackets and I want to ignore that while searching.
â Alex Raj Kaliamoorthy
Jan 4 at 14:13
add a comment |Â
up vote
1
down vote
grep seems to do what you want.
grep 'word' filename
Will print every line in the file 'filename' that contains 'word'.
I have tried this already but if you see, my file has1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
and I need onlyc755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
. The line I need contains brackets and I want to ignore that while searching.
â Alex Raj Kaliamoorthy
Jan 4 at 14:13
add a comment |Â
up vote
1
down vote
up vote
1
down vote
grep seems to do what you want.
grep 'word' filename
Will print every line in the file 'filename' that contains 'word'.
grep seems to do what you want.
grep 'word' filename
Will print every line in the file 'filename' that contains 'word'.
answered Jan 4 at 14:08
sapensadler
48016
48016
I have tried this already but if you see, my file has1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
and I need onlyc755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
. The line I need contains brackets and I want to ignore that while searching.
â Alex Raj Kaliamoorthy
Jan 4 at 14:13
add a comment |Â
I have tried this already but if you see, my file has1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
and I need onlyc755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
. The line I need contains brackets and I want to ignore that while searching.
â Alex Raj Kaliamoorthy
Jan 4 at 14:13
I have tried this already but if you see, my file has
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
and I need only c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
. The line I need contains brackets and I want to ignore that while searching.â Alex Raj Kaliamoorthy
Jan 4 at 14:13
I have tried this already but if you see, my file has
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
and I need only c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
. The line I need contains brackets and I want to ignore that while searching.â Alex Raj Kaliamoorthy
Jan 4 at 14:13
add a comment |Â
up vote
0
down vote
Using the following, the file output appears in next line in the file after pattern search line.
sed -n '/CurrentPrincipal[MRC]/p' filename | sed -n '2p'
Output
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
sed -n '/CurrentPrincipalLegalEventAssociation/,+1p' l.txt | sed -n '2p'
Output
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
add a comment |Â
up vote
0
down vote
Using the following, the file output appears in next line in the file after pattern search line.
sed -n '/CurrentPrincipal[MRC]/p' filename | sed -n '2p'
Output
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
sed -n '/CurrentPrincipalLegalEventAssociation/,+1p' l.txt | sed -n '2p'
Output
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Using the following, the file output appears in next line in the file after pattern search line.
sed -n '/CurrentPrincipal[MRC]/p' filename | sed -n '2p'
Output
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
sed -n '/CurrentPrincipalLegalEventAssociation/,+1p' l.txt | sed -n '2p'
Output
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
Using the following, the file output appears in next line in the file after pattern search line.
sed -n '/CurrentPrincipal[MRC]/p' filename | sed -n '2p'
Output
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
sed -n '/CurrentPrincipalLegalEventAssociation/,+1p' l.txt | sed -n '2p'
Output
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
edited Jan 5 at 11:59
grg
1857
1857
answered Jan 4 at 16:06
Praveen Kumar BS
1,010128
1,010128
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f414774%2fhow-to-print-the-line-from-a-file-that-contains-the-matching-characters-in-the-p%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
I'm sorry but I don't understand what you need. Please edit your question and show us an example of your input file, including both desired and undesired lines, and then show us the output you would expect from that example.
â terdonâ¦
Jan 5 at 12:16