Separate a portion of text file into another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Separate a portion of text file into another file
# 1  
Old 08-02-2005
Separate a portion of text file into another file

Hi,

I have my input as follows :

I have given two entries-

From system Mon Aug 1 23:52:47 2005
Source !100000006!:
Impact !100000005!: High
Status ! 7!: New
Last Name+!100000001!:
First Name+ !100000003!:
Phone !100000004!:
email !100000000!: xyz@abc.com
Problem Detail !100000000!: Automated Ticket Script Problem
Script was unable to complete due to

From system Mon Aug 2 08:56:47 2005
Source !100000006!:
Impact !100000005!: High
Status ! 7!: New
Last Name+!100000001!:
First Name+ !100000003!:
Phone !100000004!:
email !100000000!: pqr@abc.com
Problem Detail !100000000!: Automated Ticket Script Problem
Script was unable to complete due to


The above is like a template and it would repeating in my input file and the would be also be updated with new entries from time to time.

What I want to do is for each entry I want to extract the email id and mail the content to that email id.

So what I thought is that if I could get each entry into a temporary file, then I could extract the email id from that and use mailx to send the mail.
But how should I go about separating the entries is the big problem.
Please Help.
Any other approaches to the problem are also welcome.

Thanks in advance,
srikanth
# 2  
Old 08-02-2005
something along these lines - not tested.

nawk -f sri.awk myInputFile

sri.awk:
Code:
BEGIN {
  FS=RS=""
}
{
  for(i=1; i <= NF; i++)
    if( match($i, "^email.*!:") ) {
       addr=substr($i, RSTART+RLENGTH+1)
       break;
    }
    printf("addr->[%s]\n", addr)
    cmd= "mailx " addr
    print | cmd
    close(cmd)
}

# 3  
Old 08-03-2005
Thanks Vgersh,

But it did not work. This was the output which I got when I ran it with my input.


addr->[]
No mail for fe598
addr->[]
No mail for fe598
addr->[]
No mail for fe598
addr->[]
No mail for fe598
addr->[]
No mail for fe598
addr->[]
No mail for fe598


Regards,
srikanth.
# 4  
Old 08-03-2005
here's the output I get based on the sample input file you've provided:
Code:
nawk -f sri.awk sample.txt 
addr->[xyz@abc.com]
addr->[pqr@abc.com]

Validate your real file jives with what you've posted originally.
# 5  
Old 08-05-2005
Thanks

Thanks a lot Vgersh99 for your inputs
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do I separate a portion of a file name to use grep on?

I'm trying to write a script that takes a file name in the form of Name_Num1_Num2.Extension and I want to separate the name portion and then use grep to see if that name part has any illegal characters in it. I already have my grep command written and it works, I'm not sure how to separate the... (5 Replies)
Discussion started by: steezuschrist96
5 Replies

2. UNIX for Beginners Questions & Answers

Ls to text file on separate lines

hi, I'm trying to print out the contents of a folder into a .txt file. The code I'm trying amongst variations is: ls -1 > filenames.txt but it prints them all on the same line ie. image102.bmpimage103.bmpimage104.bmpimage105.bmpimage106.bmp how can I change this? Please... (2 Replies)
Discussion started by: newbie100
2 Replies

3. Shell Programming and Scripting

How to grep a log file for words listed in separate text file?

Hello, I want to grep a log ("server.log") for words in a separate file ("white-list.txt") and generate a separate log file containing each line that uses a word from the "white-list.txt" file. Putting that in bullet points: Search through "server.log" for lines that contain any word... (15 Replies)
Discussion started by: nbsparks
15 Replies

4. Shell Programming and Scripting

Separate Text File into Two Lists Using Python

Hello, I have a pretty simple question, but I am new to Python and am trying to write a simple program. Put simply, I want to take a text file that looks like this: 11111 22222 33333 44444 55555 66666 77777 88888 and produce two lists, one containing the contents of the left column, one the... (0 Replies)
Discussion started by: Tyler_92
0 Replies

5. Shell Programming and Scripting

Splitting text file into 2 separate files ??

Hi All, I am new to this forumn as well to the UNIX, I have basic knowledge of UNIX which I studied some years ago, now I have to do some shell scripting to load data into Oracle database using sqlldr utility, whcih I am able to do. I have a requirement where I need to do following operation. I... (10 Replies)
Discussion started by: shekharjchandra
10 Replies

6. Shell Programming and Scripting

parsing a portion of Data from a text file

Hi All, I need some help to effectively parse out a subset of results from a big results file. Below is an example of the text file. Each block that I need to parse starts with "Output of GENE for sequence file 100.fasta" (next block starts with another number). I have given the portion of... (8 Replies)
Discussion started by: Lucky Ali
8 Replies

7. Shell Programming and Scripting

Extracting a portion of data from a very large tab delimited text file

Hi All I wanted to know how to effectively delete some columns in a large tab delimited file. I have a file that contains 5 columns and almost 100,000 rows 3456 f g t t 3456 g h 456 f h 4567 f g h z 345 f g 567 h j k lThis is a very large data file and tab delimited. I need... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

8. Shell Programming and Scripting

Separate lines from text file

I have a text file with lot of rows like.. Action & Adventure|2012: Supernova NR|2009-11-01 00:01:00|2010-05-01 23:59:00|Active|3 Action & Adventure|50 Dead Men Walking|2010-01-05 00:01:00|2010-06-30 23:59:00|Active|3 Action & Adventure|Afterwards|2009-11-26 00:01:00|2010-03-26... (3 Replies)
Discussion started by: ramse8pc
3 Replies

9. Shell Programming and Scripting

How to extract a text portion from a file

Can some one help me with shell script to extract a text block between two known strings. The given input file is as below: Name: abs Some tesxt.... Some tesxt.... Some tesxt.... end of text Name: xyz Some tesxt.... Some tesxt.... Some tesxt.... end of text Name: efg Some... (5 Replies)
Discussion started by: ejazs0
5 Replies

10. UNIX for Dummies Questions & Answers

How to extract a portion of text from a log file

I am using Unix on Mac OS X 10.5.6. I am trying to extract the last entry of a log (text) file. As seen below, each log entry looks like the following (date and time change with each log entry): I want the script to extract everything quoted above, including the "===" dividers. ... (2 Replies)
Discussion started by: atilano
2 Replies
Login or Register to Ask a Question