Grep for multiple string

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Grep for multiple string
# 8  
Old 02-12-2018
Quote:
find the second last and last word before any full stop and print them separated by a space character
yes this perfect.
sorry im not changing my mind but just trying to get the correct command.
im new here so apologies for any inconvenience caused.
# 9  
Old 02-12-2018
I only can repeat what I said in post#4. Your chances to get reasonable help increase with the amount of carefully gathered details in your spec.
Try
Code:
sed -rn 's/([^ ]* [^ ]*\.)/\n\n\1\n/; T; s/\n$//; s/^.*\n\n//; P; D;' file
d lift.
body lift.
weight loss.

# 10  
Old 02-12-2018
Quote:
find the second last and last word before any full stop and print them separated by a space character
yes this is exactly what i want.
sorry about the confusion and thanks for helping again.

---------- Post updated at 12:26 PM ---------- Previous update was at 12:22 PM ----------

ok checking the command now.
# 11  
Old 02-12-2018
@ahfze .. cause you said firstly in example, word is at first line, then differ it. Sed not works, use grep PCRE regex instead:

Code:
$ echo 'A circumferential abdominoplasty is an extended abdominoplasty plus a d lift. The resulting scar runs all the way around the body, and the operation is also called a Belt Lipectomy or lower body lift. This operation is most appropriate for patients who have undergone massive weight loss.' >string

$ grep -Po -e '(\w+)\s+(\w+\.)' string
d lift.
body lift.
weight loss.


Last edited by abdulbadii; 02-12-2018 at 09:24 PM..
This User Gave Thanks to abdulbadii For This Post:
# 12  
Old 02-13-2018
thanks abdulbadii
the grep code you provided works better.
much appreciated
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep multiple words in a file with help of fixed string switch

I have multiple strings in a file which have special character $, when i search strings by ignoring $ with \ using single quotes it returns empty results. My search strings are set char_1($lock) and set new_char_clear_3($unlock) I tried searching with but it returns empty results.However... (3 Replies)
Discussion started by: g_eashwar
3 Replies

2. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

3. Shell Programming and Scripting

Single grep to multiple strings with separate output per string

I need to grep multiple strings from a particular file. I found the use of egrep "String1|String2|String3" file.txt | wc-l Now what I'm really after is that I need to separate word count per each string found. I am trying to keep it to use the grep only 1 time. Can you guys help ? ... (9 Replies)
Discussion started by: nms
9 Replies

4. Shell Programming and Scripting

Multiple Results of Grep in one Line/String?

Hello, I have a Textfile sees like this "Word1":aksdfjaksdf "Word2":askdfjalsdkfdlsjfasldfj "This is Word3":asdfkjalskdfj what i need is a string which sees like this Word1;Word2;This is Word3 Conclusion always the text within "" which is before the : i tried it with grep.... (10 Replies)
Discussion started by: SwordMaster
10 Replies

5. Shell Programming and Scripting

Grep multiple string from input

How can I grep multiple strings from an input, strings are separated by space. Strings to grep: 7680FR 6791HH 1234AA Input: AA 7680FR AA 6891HH AA 6791UA BB 9834HA BB 1434AB DD 1234AA DD 6991HH DD 6791HH Required output: AA 7680FR (9 Replies)
Discussion started by: aydj
9 Replies

6. Shell Programming and Scripting

Grep from multiple patterns multiple file multiple output

Hi, I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command. Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns. Xargs -I {} grep... (3 Replies)
Discussion started by: Diya123
3 Replies

7. UNIX for Dummies Questions & Answers

Grep multiple strings in multiple files using single command

Hi, I will use below command for grep single string ("osuser" is search string) ex: find . -type f | xarg grep -il osuser but i have one more string "v$session" here i want to grep in which file these two strings are present. any help is appreciated, Thanks in advance. Gagan (2 Replies)
Discussion started by: gagan4599
2 Replies

8. UNIX for Dummies Questions & Answers

how to use grep: finding a string with double quotes and multiple digits

I have a file with a lot of lines (a lot!) that contain 10 digits between double quotes. ie "1726937489". The digits are random throughout, but always contain ten digits. I can not for the life of me, (via scouring the internet and grep how-to manuals) figure out how to find this when I search.... (3 Replies)
Discussion started by: titusbass
3 Replies

9. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

10. UNIX for Dummies Questions & Answers

problem with grep on search string in a txt file over multiple files

I have a couple of things I got stuck on 1) I have a text file containing 25k search string that I need to search against compressed file. I have used this command but somehow it doesn't seems to use all the search terms. I have put one search string per line in the txt file (I clean up... (2 Replies)
Discussion started by: m00
2 Replies
Login or Register to Ask a Question