Solved

Delete Blank Lines From A File

Posted on 2011-09-14
9
403 Views
Last Modified: 2012-05-12
Trying to delete blank lines from an Oracle SQLFILE.  I've tried sed '/^$/d' filename and going into vi then : /^$/d.  Neither works.
set list
-- new object type path is: DATABASE_EXPORT/SCHEMA/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT$
-- CONNECT OUTLN$
GRANT SELECT ON "OUTLN"."OL$" TO "SELECT_CATALOG_ROLE";$
 $
GRANT SELECT ON "OUTLN"."OL$HINTS" TO "SELECT_CATALOG_ROLE";$
 $
-- CONNECT SYSTEM$
GRANT SELECT ON "SYSTEM"."DEF$_AQCALL" TO "SYS" WITH GRANT OPTION;$
 $
GRANT SELECT ON "SYSTEM"."DEF$_ERROR" TO "SYS" WITH GRANT OPTION;$
 $
GRANT SELECT ON "SYSTEM"."DEF$_DESTINATION" TO "SYS" WITH GRANT OPTION;$
 $
GRANT SELECT ON "SYSTEM"."DEF$_CALLDEST" TO "SYS" WITH GRANT OPTION;$
 $
GRANT SELECT ON "SYSTEM"."DEF$_LOB" TO "SYS" WITH GRANT OPTION;$
 $
GRANT DELETE ON "SYSTEM"."DEF$_TEMP$LOB" TO "SYS" WITH GRANT OPTION;$
:set list
0
Comment
Question by:xoxomos
  • 5
  • 3
9 Comments
 
LVL 77

Expert Comment

by:arnold
ID: 36540110
Is the line really blank or is it spaces filled?
cat filename | egrep -v '^\s+\$'  
0
 
LVL 7

Expert Comment

by:jackiechen858
ID: 36543884
grep -v "^\s*$"  filename

can remove blank line or lines with only spaces.
0
 

Author Comment

by:xoxomos
ID: 36544073
Blank lines remain
oracle@bb7b:/u05/datapump_directory$ grep -v "^\s*$" create_user.sql
-- new object type path is: DATABASE_EXPORT/SYS_USER/USER
 ALTER USER "SYS" IDENTIFIED BY VALUES 'BBFEC2ABA14349B0'
      TEMPORARY TABLESPACE "TEMP";
 
-- new object type path is: DATABASE_EXPORT/SCHEMA/USER
 ALTER USER "SYSTEM" IDENTIFIED BY VALUES 'E3C232DAD21E66AE'
      DEFAULT TABLESPACE "TOOLS"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "OUTLN" IDENTIFIED BY VALUES '4A3BA55E08595C81'
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "TRACESVR" IDENTIFIED BY VALUES 'F9DA8977092B7B81'
      DEFAULT TABLESPACE "SMALL_DEFAULT"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "BBADMIN" IDENTIFIED BY VALUES '35DE13A3ED9CDD95'
      DEFAULT TABLESPACE "BBADMIN_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "BB_BB60_STATS" IDENTIFIED BY VALUES 'DD5B4DC833EE258E'
      DEFAULT TABLESPACE "BB_BB60_STATS_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "BB_BB60" IDENTIFIED BY VALUES '7EFB15396EAF1168'
      DEFAULT TABLESPACE "BB_BB60_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CSUH_CUSTOM" IDENTIFIED BY VALUES 'E038316871F962A3'
      DEFAULT TABLESPACE "USERS"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "TOAD" IDENTIFIED BY VALUES '4759257F78A8B5A3'
      DEFAULT TABLESPACE "USERS"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "MONITOR" IDENTIFIED BY VALUES 'C15C7CCC01A60009'
      DEFAULT TABLESPACE "USERS"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "BBUSER" IDENTIFIED BY VALUES '80D18B7604314C8E'
      DEFAULT TABLESPACE "USERS"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS_FILES_USERS" IDENTIFIED BY VALUES '5847C9D3918C97A2'
      DEFAULT TABLESPACE "CMS_FILES_USERS_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS_FILES_ORGS" IDENTIFIED BY VALUES 'AFB576C50494B4C1'
      DEFAULT TABLESPACE "CMS_FILES_ORGS_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS_FILES_LIBRARY" IDENTIFIED BY VALUES '7AEB5FC2E127D8C0'
      DEFAULT TABLESPACE "CMS_FILES_LIBRARY_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS_FILES_INST" IDENTIFIED BY VALUES '068EFD7044613CA2'
      DEFAULT TABLESPACE "CMS_FILES_INST_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS_FILES_COURSES" IDENTIFIED BY VALUES 'F9A622520FAD900B'
      DEFAULT TABLESPACE "CMS_FILES_COURSES_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS" IDENTIFIED BY VALUES 'C64584543210EBE1'
      DEFAULT TABLESPACE "CMS_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "TSMSYS" IDENTIFIED BY VALUES '3DF26A8B17D0F29F'
      DEFAULT TABLESPACE "SMALL_DEFAULT"
      TEMPORARY TABLESPACE "TEMP"
      PASSWORD EXPIRE
      ACCOUNT LOCK;
 
 CREATE USER "BB_BB60_REPORT" IDENTIFIED BY VALUES 'F380EA59E2ABA7AE'
      DEFAULT TABLESPACE "BB_BB60_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS_DOC" IDENTIFIED BY VALUES '43F8F151C0F109AB'
      DEFAULT TABLESPACE "CMS_DOC_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "SYSMAN" IDENTIFIED BY VALUES '921843AF2EA8AFA2'
      DEFAULT TABLESPACE "SYSAUX"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "MGMT_VIEW" IDENTIFIED BY VALUES 'B2E0DCB0078F8133'
      TEMPORARY TABLESPACE "TEMP";
oracle@bb7b:/u05/datapump_directory$
0
 

Author Comment

by:xoxomos
ID: 36544091
Blank lines remain
oracle@bb7b:/u05/datapump_directory$ grep -v "^\s*$" create_user.sql
-- new object type path is: DATABASE_EXPORT/SYS_USER/USER
 ALTER USER "SYS" IDENTIFIED BY VALUES 'BBFEC2ABA14349B0'
      TEMPORARY TABLESPACE "TEMP";
 
-- new object type path is: DATABASE_EXPORT/SCHEMA/USER
 ALTER USER "SYSTEM" IDENTIFIED BY VALUES 'E3C232DAD21E66AE'
      DEFAULT TABLESPACE "TOOLS"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "OUTLN" IDENTIFIED BY VALUES '4A3BA55E08595C81'
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "TRACESVR" IDENTIFIED BY VALUES 'F9DA8977092B7B81'
      DEFAULT TABLESPACE "SMALL_DEFAULT"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "BBADMIN" IDENTIFIED BY VALUES '35DE13A3ED9CDD95'
      DEFAULT TABLESPACE "BBADMIN_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "BB_BB60_STATS" IDENTIFIED BY VALUES 'DD5B4DC833EE258E'
      DEFAULT TABLESPACE "BB_BB60_STATS_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "BB_BB60" IDENTIFIED BY VALUES '7EFB15396EAF1168'
      DEFAULT TABLESPACE "BB_BB60_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CSUH_CUSTOM" IDENTIFIED BY VALUES 'E038316871F962A3'
      DEFAULT TABLESPACE "USERS"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "TOAD" IDENTIFIED BY VALUES '4759257F78A8B5A3'
      DEFAULT TABLESPACE "USERS"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "MONITOR" IDENTIFIED BY VALUES 'C15C7CCC01A60009'
      DEFAULT TABLESPACE "USERS"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "BBUSER" IDENTIFIED BY VALUES '80D18B7604314C8E'
      DEFAULT TABLESPACE "USERS"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS_FILES_USERS" IDENTIFIED BY VALUES '5847C9D3918C97A2'
      DEFAULT TABLESPACE "CMS_FILES_USERS_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS_FILES_ORGS" IDENTIFIED BY VALUES 'AFB576C50494B4C1'
      DEFAULT TABLESPACE "CMS_FILES_ORGS_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS_FILES_LIBRARY" IDENTIFIED BY VALUES '7AEB5FC2E127D8C0'
      DEFAULT TABLESPACE "CMS_FILES_LIBRARY_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS_FILES_INST" IDENTIFIED BY VALUES '068EFD7044613CA2'
      DEFAULT TABLESPACE "CMS_FILES_INST_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS_FILES_COURSES" IDENTIFIED BY VALUES 'F9A622520FAD900B'
      DEFAULT TABLESPACE "CMS_FILES_COURSES_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS" IDENTIFIED BY VALUES 'C64584543210EBE1'
      DEFAULT TABLESPACE "CMS_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "TSMSYS" IDENTIFIED BY VALUES '3DF26A8B17D0F29F'
      DEFAULT TABLESPACE "SMALL_DEFAULT"
      TEMPORARY TABLESPACE "TEMP"
      PASSWORD EXPIRE
      ACCOUNT LOCK;
 
 CREATE USER "BB_BB60_REPORT" IDENTIFIED BY VALUES 'F380EA59E2ABA7AE'
      DEFAULT TABLESPACE "BB_BB60_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CMS_DOC" IDENTIFIED BY VALUES '43F8F151C0F109AB'
      DEFAULT TABLESPACE "CMS_DOC_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "SYSMAN" IDENTIFIED BY VALUES '921843AF2EA8AFA2'
      DEFAULT TABLESPACE "SYSAUX"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "MGMT_VIEW" IDENTIFIED BY VALUES 'B2E0DCB0078F8133'
      TEMPORARY TABLESPACE "TEMP";
oracle@bb7b:/u05/datapump_directory$
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:xoxomos
ID: 36544094
racle@bb7b:/u05/datapump_directory$ cat create_user.sql  | egrep -v '^\s+\$'  
-- new object type path is: DATABASE_EXPORT/SYS_USER/USER
 ALTER USER "SYS" IDENTIFIED BY VALUES 'BBFEC2ABA14349B0'
      TEMPORARY TABLESPACE "TEMP";
 
-- new object type path is: DATABASE_EXPORT/SCHEMA/USER
 ALTER USER "SYSTEM" IDENTIFIED BY VALUES 'E3C232DAD21E66AE'
      DEFAULT TABLESPACE "TOOLS"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "OUTLN" IDENTIFIED BY VALUES '4A3BA55E08595C81'
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "TRACESVR" IDENTIFIED BY VALUES 'F9DA8977092B7B81'
      DEFAULT TABLESPACE "SMALL_DEFAULT"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "BBADMIN" IDENTIFIED BY VALUES '35DE13A3ED9CDD95'
      DEFAULT TABLESPACE "BBADMIN_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "BB_BB60_STATS" IDENTIFIED BY VALUES 'DD5B4DC833EE258E'
      DEFAULT TABLESPACE "BB_BB60_STATS_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "BB_BB60" IDENTIFIED BY VALUES '7EFB15396EAF1168'
      DEFAULT TABLESPACE "BB_BB60_DATA"
      TEMPORARY TABLESPACE "TEMP";
 
 CREATE USER "CSUH_CUSTOM" IDENTIFIED BY VALUES 'E038316871F962A3'
      DEFAULT TABLESPACE "USERS"
      TEMPORARY TABLESPACE "TEMP";
0
 
LVL 77

Expert Comment

by:arnold
ID: 36544206
The problem is that to exclude something you have to know what is there

What is the issue that the blank lines are causing which leads you to have the need to have them removed??

try cat create_user.sql | grep -i '(alter|default|tablespace|path)'

0
 
LVL 77

Accepted Solution

by:
arnold earned 300 total points
ID: 36544351
try
cat create_user.sql | egrep -i '[a-z0-9\-]'
 
0
 

Author Comment

by:xoxomos
ID: 36544746
cat create_user.sql | egrep -i '[a-z0-9\-]' > create_users.sql
 :-)  :-)  :-)

Basically i want to use it as a SQL script.  In all there are 800,000+ lines involved.
If I go into SQLPlus and call that as a script it will error out on any blank line between statements.
Thanks
0
 

Author Closing Comment

by:xoxomos
ID: 36544751
Mil gracias
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now