![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to remove user from a group using command line | civic2005 | SUN Solaris | 2 | 09-18-2008 03:05 PM |
| print any required line by its line no using awk and its NR variable | RahulJoshi | Shell Programming and Scripting | 2 | 09-07-2008 03:35 AM |
| How to print the output in single line | Prat007 | Shell Programming and Scripting | 1 | 08-03-2008 05:41 AM |
| How do i print this output all on the same line? | rcon1 | UNIX for Dummies Questions & Answers | 1 | 02-05-2008 10:52 AM |
| locating the line and print the output | vasikaran | UNIX for Dummies Questions & Answers | 7 | 08-03-2005 09:57 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
awk help required to group output and print a part of group line and original line
Hello World Postbit Hi,
Need awk help to group and print lines to format the output as shown below INPUT FORMAT set echo on set heading on set spool on /* SCHEMA1 */ CREATE TABLE T1; /* SCHEMA1 */ CREATE TABLE T2; /* SCHEMA1 */ CREATE TABLE T3; /* SCHEMA1 */ CREATE TABLE T4; /* SCHEMA1 */ CREATE TABLE T5; /* SCHEMA2 */ CREATE TABLE T1; /* SCHEMA2 */ CREATE TABLE T2; /* SCHEMA2 */ CREATE TABLE T3; /* SCHEMA3 */ CREATE TABLE T1; /* SCHEMA3 */ CREATE TABLE T2; /* SCHEMA3 */ CREATE TABLE T3; /* SCHEMA4 */ CREATE TABLE T1; set feedback on set spool off DESIRED OUTPUT set echo on set heading on set spool on connect SCHEMA1 /* SCHEMA1 */ CREATE TABLE T1; /* SCHEMA1 */ CREATE TABLE T2; /* SCHEMA1 */ CREATE TABLE T3; /* SCHEMA1 */ CREATE TABLE T4; /* SCHEMA1 */ CREATE TABLE T5; connect SCHEMA2 /* SCHEMA2 */ CREATE TABLE T1; /* SCHEMA2 */ CREATE TABLE T2; /* SCHEMA2 */ CREATE TABLE T3; connect SCHEMA3 /* SCHEMA3 */ CREATE TABLE T1; /* SCHEMA3 */ CREATE TABLE T2; /* SCHEMA3 */ CREATE TABLE T3; connect SCHEMA4 /* SCHEMA4 */ CREATE TABLE T1; set feedback on set spool off I am looking forward to add the connect lines where all the SQL lines start with /* SCHEMAn */ values as a consistent pattern i was able to sort the distict values of the pattern using the below awk nawk '/^\/\* /{dup[$2]++;if (dup[$2]>=1){name[$2]=$2}};END{for(i in name)print name[i]} ' inputfile Output ------- SCHEMA1 SCHEMA2 SCHEMA3 SCHEMA4 but i am not sure how to place these lines in before the patterns and skip till the next pattern is found. Thanks in advance, Rajan |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|