Serach and delete


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Serach and delete
# 1  
Old 10-24-2006
Serach and delete

Hi,
This is the format of the file that i have
CompanyNumber Run Date: 8/3/2006
6:22:15PM

Address:

Person: A03120
SP SNNu
100 1
200 2



CompanyNumber Run Date: 8/3/2006
6:22:15PM

Address:

Person: A03562


SP SNNu
100 1
200 2



i want to delete all the lines between CompanyNumber and Address: and add a new column called as person id to the o/p


this is the o/p that i need



Person SP SNNu
A03120 100 1
A03120 200 2

Person SP SNNu
A03562 100 1
A03562 200 2



Thanks
kk
# 2  
Old 10-24-2006
try something like this :
Code:
#!/bin/ksh

sed '/^Company/,/^Address/d;/^$/d' filename |\
awk '{ if (match($0,"^Person")) { person=$2; print " "; printf "Person ";continue }
       print person, $0 
    }'

# 3  
Old 10-24-2006
Another awk try

Code:
sed '/^$/d' inpfilename | awk -f awkfile ;

where awkfile contains

Code:
/Person/ {
 i=0;
 name=$2
 getline; printf("%-10s%10s%10s\n", "Person", $1,$2);
 getline
 while($1 != "CompanyNumber" || $1 == "" )
 { 
  sp[i]=$1; snnu[i]=$2;
  i++;
  if(getline == 0) break;
 }
 for(cnt=0;cnt<i;cnt++)
 {
  printf("%-10s%10s%10s\n",name,sp[cnt],snnu[cnt]);
 }
 printf("\n");
}

# 4  
Old 10-25-2006
Code:
awk '/^Person:/{
per=$2;getline title;
while(match(title,"^ *$")) getline title;
getline;
printf("Person %s\n",title);
printf("%s %s\n",per,$0);
getline;
printf("%s %s\n\n",per,$0);
}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get a value from a file and serach that value filename in a dir?

buddies, my requirement would be as follows, I have a file called test.txt and content of it would be yahoo gmail hotmail and i want to search a file name called "yahoo.html" (first line of test.txt) and then "gmail.html" and then "hotmail.html" in a /home/test dir. Any idea... (8 Replies)
Discussion started by: natraj005
8 Replies

2. Shell Programming and Scripting

Serach a keyword based on last updated

Hi, Can you guys help in writing script based upon my requirement. The requirement is : Th script should poll or sniff an log file every minute or every second. The log file name is "license.txt" In the log file if it founds "not valid" then it should send mail to a group. the logic... (3 Replies)
Discussion started by: rockingvj
3 Replies

3. UNIX for Dummies Questions & Answers

Serach pattern in one field and replace in another

Hi all, I have a TAB separated file like this: sample.rpt: 54 67 common/bin/my/home {{bla bla bla}} {bla bla} Replace Me 89 75 bad/rainy/day/out {{ some bla} } {some bla} Dontreplace Me ...... ...... I wish to do a regexp match on the 3rd... (2 Replies)
Discussion started by: newboy
2 Replies

4. UNIX for Dummies Questions & Answers

Serach a pattern

Hi, I am trying to find a particular patter in multiple UNIX files (also contain system files,hidden files and normal files) i am now using CMD: egrep -ali 'pattern' * i am not getting the required result, i just need files path and finename Naveen (3 Replies)
Discussion started by: Naveen_5960
3 Replies

5. Shell Programming and Scripting

WildCard serach for files in a directory

Hi i have a requirement to search for all files in a directory. the files will start as file1_*,file2_*,file3_* where the wild card character is a timestamp. so on a particular day i may get files like file1_1103120042 file1_1102010345 file2_1101093423 file3_1103120042... (3 Replies)
Discussion started by: Sgiri1
3 Replies

6. Shell Programming and Scripting

pattern serach using grep

Frds I have to search for a string which is starting with brighton which will be first in the line of a text file test1.txt. The contents of test1.txt are file names like ----- brighton brighton_gt hst_brighton gst_brighton -------so many files------ --------- i have retrieve only... (3 Replies)
Discussion started by: KiranKumarKarre
3 Replies

7. UNIX for Dummies Questions & Answers

Pattern Matching - serach and replace script

My requirement is to replace a a particular pattren in a script from A to B. I am not sure if this can be done through sed command or through awk . The file sv.inc is window DialogBox AddConnection tag "~ActiveApp/Add Connection - Provider Type?URL" I would wnat the file to be... (10 Replies)
Discussion started by: bsandeep_80
10 Replies

8. Shell Programming and Scripting

serach file using awk

Hi, I was able to print lines when search for specific string using awk but i want to print when search for two different strings using awk instead of doing two times (Print lines only contain "Insert Records and Insert into" not between lines) Ex: awk '/Insert Records./' a4.log It... (3 Replies)
Discussion started by: mohan705
3 Replies

9. Shell Programming and Scripting

Case-insensitive serach with awk

Is there any way to do case insensitive search with awk for the below statement: month1=`awk '/month/' ${trgfile} | cut -d"=" -f2` the "month" could come as Month, mOnth,MONTH etc. in a file. Now I am looking for "month".... Thanks, AC (4 Replies)
Discussion started by: acheepi
4 Replies

10. UNIX for Advanced & Expert Users

text serach in unknown file

Can any one tell me if there is an easy way to find a text in an unknown file name in a dierectory. I'm trying to search for the text "where is john going" from a file whose name I do not even know. There are about 1000 files in that directory and one of the files has this text in it. Can... (11 Replies)
Discussion started by: ted
11 Replies
Login or Register to Ask a Question