Search for multiple pattern in same line
up vote
2
down vote
favorite
I'm trying to search for different patterns in the same line and then print them in this way.
This is the text:
`voices` VALUES (409663,1957,2594,'mech Brands LC - BO GB6: pic - LST September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');
`others` VALUES (409664,1957,2595,'mech Brands LC - BO NZ6: pic - LST September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');
`voices` VALUES (409684,628,2622,'Pic Productions Com - pic: perV things September 2017',NULL,1,0,'2017-09-24 07:35:22',NULL,NULL,628,0,0,NULL,'2017-09-24 07:35:22');
And I would like to output like this:
`voices` - mech Brands LC
`others` - mech Brands LC
`voices` - Pic Productions Com
This is what I have tried but it gives me the output in different lines
cat file.txt | grep -Pzo "mech Brands LC|Pic Productions Com|`.*`"
`invoices`
mech Brands LC
`invoices`
mech Brands LC
`invoices`
Pic Productions Com
Could somebody help me?
Thanks!
mysql search
add a comment |
up vote
2
down vote
favorite
I'm trying to search for different patterns in the same line and then print them in this way.
This is the text:
`voices` VALUES (409663,1957,2594,'mech Brands LC - BO GB6: pic - LST September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');
`others` VALUES (409664,1957,2595,'mech Brands LC - BO NZ6: pic - LST September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');
`voices` VALUES (409684,628,2622,'Pic Productions Com - pic: perV things September 2017',NULL,1,0,'2017-09-24 07:35:22',NULL,NULL,628,0,0,NULL,'2017-09-24 07:35:22');
And I would like to output like this:
`voices` - mech Brands LC
`others` - mech Brands LC
`voices` - Pic Productions Com
This is what I have tried but it gives me the output in different lines
cat file.txt | grep -Pzo "mech Brands LC|Pic Productions Com|`.*`"
`invoices`
mech Brands LC
`invoices`
mech Brands LC
`invoices`
Pic Productions Com
Could somebody help me?
Thanks!
mysql search
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm trying to search for different patterns in the same line and then print them in this way.
This is the text:
`voices` VALUES (409663,1957,2594,'mech Brands LC - BO GB6: pic - LST September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');
`others` VALUES (409664,1957,2595,'mech Brands LC - BO NZ6: pic - LST September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');
`voices` VALUES (409684,628,2622,'Pic Productions Com - pic: perV things September 2017',NULL,1,0,'2017-09-24 07:35:22',NULL,NULL,628,0,0,NULL,'2017-09-24 07:35:22');
And I would like to output like this:
`voices` - mech Brands LC
`others` - mech Brands LC
`voices` - Pic Productions Com
This is what I have tried but it gives me the output in different lines
cat file.txt | grep -Pzo "mech Brands LC|Pic Productions Com|`.*`"
`invoices`
mech Brands LC
`invoices`
mech Brands LC
`invoices`
Pic Productions Com
Could somebody help me?
Thanks!
mysql search
I'm trying to search for different patterns in the same line and then print them in this way.
This is the text:
`voices` VALUES (409663,1957,2594,'mech Brands LC - BO GB6: pic - LST September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');
`others` VALUES (409664,1957,2595,'mech Brands LC - BO NZ6: pic - LST September 2017',NULL,1,0,'2017-09-24 07:35:18',NULL,NULL,1957,0,0,NULL,'2017-09-24 07:35:18');
`voices` VALUES (409684,628,2622,'Pic Productions Com - pic: perV things September 2017',NULL,1,0,'2017-09-24 07:35:22',NULL,NULL,628,0,0,NULL,'2017-09-24 07:35:22');
And I would like to output like this:
`voices` - mech Brands LC
`others` - mech Brands LC
`voices` - Pic Productions Com
This is what I have tried but it gives me the output in different lines
cat file.txt | grep -Pzo "mech Brands LC|Pic Productions Com|`.*`"
`invoices`
mech Brands LC
`invoices`
mech Brands LC
`invoices`
Pic Productions Com
Could somebody help me?
Thanks!
mysql search
mysql search
edited Nov 20 at 9:16
juergen d
158k24199259
158k24199259
asked Nov 20 at 9:16
mmac-rio89
3329
3329
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I suggest using sed for this:
sed 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt
Or, with POSIX ERE syntax
sed -E 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt
See the online sed demo
Details
^- start of string
(`[^`]*`)- Group 1: a backtick, 0+ chars other than backticks and a backtick
.*- any 0+ chars
(mech Brands LC|Pic Productions Com)- Group 2: eithermech Brands LCorPic Productions Comsubstrings
.*- any 0+ chars
1 - 2- the match is replaced with Group 1,-and Group 2 values.
1
Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
– mmac-rio89
Nov 20 at 10:07
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I suggest using sed for this:
sed 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt
Or, with POSIX ERE syntax
sed -E 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt
See the online sed demo
Details
^- start of string
(`[^`]*`)- Group 1: a backtick, 0+ chars other than backticks and a backtick
.*- any 0+ chars
(mech Brands LC|Pic Productions Com)- Group 2: eithermech Brands LCorPic Productions Comsubstrings
.*- any 0+ chars
1 - 2- the match is replaced with Group 1,-and Group 2 values.
1
Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
– mmac-rio89
Nov 20 at 10:07
add a comment |
up vote
1
down vote
accepted
I suggest using sed for this:
sed 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt
Or, with POSIX ERE syntax
sed -E 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt
See the online sed demo
Details
^- start of string
(`[^`]*`)- Group 1: a backtick, 0+ chars other than backticks and a backtick
.*- any 0+ chars
(mech Brands LC|Pic Productions Com)- Group 2: eithermech Brands LCorPic Productions Comsubstrings
.*- any 0+ chars
1 - 2- the match is replaced with Group 1,-and Group 2 values.
1
Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
– mmac-rio89
Nov 20 at 10:07
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I suggest using sed for this:
sed 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt
Or, with POSIX ERE syntax
sed -E 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt
See the online sed demo
Details
^- start of string
(`[^`]*`)- Group 1: a backtick, 0+ chars other than backticks and a backtick
.*- any 0+ chars
(mech Brands LC|Pic Productions Com)- Group 2: eithermech Brands LCorPic Productions Comsubstrings
.*- any 0+ chars
1 - 2- the match is replaced with Group 1,-and Group 2 values.
I suggest using sed for this:
sed 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt
Or, with POSIX ERE syntax
sed -E 's/^(`[^`]*`).*(mech Brands LC|Pic Productions Com).*/1 - 2/' file.txt > newfile.txt
See the online sed demo
Details
^- start of string
(`[^`]*`)- Group 1: a backtick, 0+ chars other than backticks and a backtick
.*- any 0+ chars
(mech Brands LC|Pic Productions Com)- Group 2: eithermech Brands LCorPic Productions Comsubstrings
.*- any 0+ chars
1 - 2- the match is replaced with Group 1,-and Group 2 values.
answered Nov 20 at 9:27
Wiktor Stribiżew
305k16123201
305k16123201
1
Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
– mmac-rio89
Nov 20 at 10:07
add a comment |
1
Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
– mmac-rio89
Nov 20 at 10:07
1
1
Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
– mmac-rio89
Nov 20 at 10:07
Thank you so much for your Help @Wiktor!!! This helped me to solve my problem! :)
– mmac-rio89
Nov 20 at 10:07
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389697%2fsearch-for-multiple-pattern-in-same-line%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown