First: you can write almost any awk script in one line. For anything this complex, however, I would never do that. I will take readable (and maintainable) over single-line every time.
Second: RudiC gave you a good starting point to reach your goal. If you are playing a game to see if you can get volunteers from the UNIX and Linux Forum to write code for you (with increasing complex requirements as the thread goes on), that isn't what we're here for. We want to help you learn how to write your own code; not act as your unpaid programming staff.
Third: Your requirements are confusing and inconsistent. First you say:
Quote:
I wish to search for and output these patterns in order;
Note that "From: " is not in this list. Note that "To: " is in this list twice. Then you say that the output your want is:
Quote:
which has output in the order:
I could assume that the 1st "To: " from the 1st quote above was a typo and that "From: " was the intended header. But, why is "Date: Date: " expected to be part of your output. And, where is there just a <space> between the From: data and the Subject: data instead of <space><tab><space> that you apparently want between the other fields? Why do you want <space><tab><space> separators between fields instead of just a <tab>?
Then you say:
Quote:
Problem 3;
If one of the patterns doesn't match, can a string "Blank" be used as a result ?
But, you don't show us any example of what that should look like in the output. If, for example, there is no Subject: line in a mail message, are you hoping to get: Subject: "Blank", Subject: Blank, "Blank", or Blank for the Subject: section in your output?
Please take the suggestion RudiC provided and try to modify it to meet your requirements. If you run into problems, show us what you have tried and explain where you are stuck, and we'll be happy to help you. Remember to use CODE tags when presenting sample input, output, and code segments. And, be aware that if you present a single-line attempt to solve this problem, it will make it much harder (and less likely) for us to see the structure of your code, to understand the logic behind your attempt to solve your problem, and for us to figure out what needs to be fixed to turn code that doesn't quite do what you want into code that does exactly what you want.
This User Gave Thanks to Don Cragun For This Post:
I want to get a list of all the files in the current directory that have two patterns. I can do first grep of one pattern and then with the output do the grep of the second pattern.
if the output of 1st pattern search results in many files, it is very difficult to do a grep of the 2nd pattern for... (1 Reply)
Hi,
Can we grep multiple patterns in UNIX.
for example:
cat /x/y/oratab | grep -i "pattern1|pattern2" .... etc
I require the syntax for multiple patterns. | is not working as I explained in example.
Malay (4 Replies)
Hi All,
I have a file. I need to find multiple patterns in a row and need those rows to divert to new file.
I tried using grep -e / -E / -F options as given in man.
But its not working.
==> cat testgrep.txt
william,fernandes,xxxxx
mark,morsov,yyyy
yy=,xx=
yyyy=,xxxx==
==>... (7 Replies)
Hi
I'm not very good with the serach patterns and I'd need a sample how to find a line that has multiple patterns.
Say I want to find a line that has "abd", "123" and "QWERTY" and there can be any characters or numbers between the serach patterns, I have a file that has thousands of lines and... (10 Replies)
I have a file with many rows.
I want to grep for multiple patterns from the file.
For eg:
XX=123|YY=222|ZZ=566
AA=123|EE=222|GG=566
FF=123|RR=222|GG=566
DD=123|RR=222|GG=566
I want the lines which has both XX and ZZ.
I know I can get it like this.
grep XX file | grep YY
But... (10 Replies)
Dear all,
I need to search multiple patterns and then I need to print their respective next lines. For an example, in the below table, I will look for 3 different patterns :
1) # ATC_Codes:
2) # Generic_Name:
3) # Drug_Target_1_Gene_Name:
#BEGIN_DRUGCARD DB00001
# AHFS_Codes:... (3 Replies)
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)
I am trying to grep a variable with multiple lines with multiple patterns
below is the pattern list in a variable called "grouplst", each pattern is speerated by "|"
grouplst="example1|example2|example3|example4|example5|example6|example7"
I need to use the patterns above to grep a... (2 Replies)
In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)