The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need to serach if a new line character exists on the last line in a file sunilbm78 UNIX for Dummies Questions & Answers 10 02-29-2008 02:15 PM
serach and replace file name in the path in a remote xml file kiranreddy1215 Shell Programming and Scripting 1 11-12-2007 11:31 AM
serach file using awk mohan705 Shell Programming and Scripting 3 08-28-2007 11:04 AM
Case-insensitive serach with awk acheepi Shell Programming and Scripting 4 07-15-2005 05:58 PM
text serach in unknown file ted UNIX for Advanced & Expert Users 11 10-23-2003 03:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-24-2006
kkm_job kkm_job is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 3
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 (permalink)  
Old 10-24-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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 (permalink)  
Old 10-24-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
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 (permalink)  
Old 10-25-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0