Sponsored Content
Top Forums Shell Programming and Scripting extracting lines from a file with similar first name Post 302583779 by vivek d r on Wednesday 21st of December 2011 08:39:27 AM
Old 12-21-2011
extracting lines from a file with similar first name

consider i have two files
Code:
cat onlyviews1.sql
CREATE VIEW V11
 AS
 SELECT id,
              name,
      FROM 
         etc etc
     WHERE     etc etc;
 
CREATE VIEW V22
 AS
 SELECT id,
              name,
      FROM 
         etc etc
     WHERE     etc etc;
 
CREATE VIEW V33
 AS
 SELECT id,
              name,
      FROM 
         etc etc
     WHERE     etc etc;

Code:
cat onlyviews2.sql
CREATE VIEW V119
 AS
 SELECT id,
              name,
      FROM 
         etc etc
     WHERE     etc etc;
 
CREATE VIEW V11
 AS
 SELECT id,
              name,
      FROM 
         etc etc
     WHERE     etc etc;
 
CREATE VIEW V22
 AS
 SELECT id,
              name,
      FROM 
         etc etc
     WHERE     etc etc;

Code:
firstword="CREATE VIEW V11"

i am performing mainly 3 actions as given below..
Code:
1) sed -n "/$firstword/,/;/p" onlyviews1.sql | awk '!x[$1]++' >viewextract1.sql
or
sed -n "/$firstword/,/;/p" onlyviews2.sql | awk '!x[$1]++' > viewextract2.sql
and
 2) viewpresent=`cat onlyviews2.sql | grep -i "$firstword" | wc | awk -F' ' '{print $1}'`
and
3) echo "`sed "/$firstword/,/;/d" onlyviews2.sql`" > onlyviews2.sql

the command (1) extracts individual view from onlyviews file to viewextract file respectively...
the command (2) checks whether a particular view is present in onlyviews2.sql or not.. that is viewpresent will be >1 if present or 0 if not
the command (3) deleted that particular view from onlyviews2.sql

now my problem is say variable $firstword has the contents as shown previously that is CREATE VIEW V11 so if i use commands it will consider V119 too in onlyviews2.sql... since "CREATE VIEW V11" is also present in ""CREATE VIEW V11"9".. so how to overcome this situation...?.... SmilieSmilieSmilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

extracting lines from a file

i want to extract lines 5 and 7 from a txt file which contains nearly 20 entries how to do it also i want to check whether the 42nd character is 'S' in that line suggestions welcome (4 Replies)
Discussion started by: trichyselva
4 Replies

2. Shell Programming and Scripting

How to sort a file and then print similar lines once

Hi! I have a trouble with the sort and the uniq. I know I have to use them, I just have trouble with putting them in the right order. I have a text file with unsorted lines (each line has a few words, the first word in the line is a number.). I need to sort this file in order to be... (6 Replies)
Discussion started by: shira
6 Replies

3. Infrastructure Monitoring

Remove Similar Lines from a File

I have a log file "logreport" that contains several lines as seen below: 04:20:00 /usr/lib/snmp/snmpdx: Agent snmpd appeared dead but responded to ping 06:38:08 /usr/lib/snmp/snmpdx: Agent snmpd appeared dead but responded to ping 07:11:05 /usr/lib/snmp/snmpdx: Agent snmpd appeared dead... (4 Replies)
Discussion started by: Nysif Steve
4 Replies

4. Shell Programming and Scripting

Counting similar lines from file UNIX

I have a file which contains data as below: nbk1j7o pageName=/jsp/RMBS/RMBSHome.jsf nbk1j7o pageName=/jsp/RMBS/RMBSHome.jsf nbk1j7o pageName=/jsp/RMBS/RMBSHome.jsf nbk1j7o pageName=/jsp/RMBS/RMBSHome.jsf nbk1j7o pageName=/jsp/common/index.jsf nbk1j7o pageName=/jsp/common/index.jsf nbk1wqe... (6 Replies)
Discussion started by: mohsin.quazi
6 Replies

5. Shell Programming and Scripting

remove one of each similar lines in a file

Hello folks I have a question for you gurus of sed or grep (maybe awk, but I would prefer the first two) I have a file (f1) that says: (actually, these are not numbers but md5sum, but for simplicity, let's assume these numbers.) 1 2 3 4 5And I have a file (f2) that says 1|a 1|b 1|c 2|d... (3 Replies)
Discussion started by: tukuyomi
3 Replies

6. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

7. UNIX for Dummies Questions & Answers

merge lines within a file that start with a similar pattern

Hello! i have a text file.. which contains the data as follows i want to merge the declarations lines pertaining to one datatype in to a single line as follows i've searched the forum for help.. but couldn't find much help.. how can i do this?? (1 Reply)
Discussion started by: a_ba
1 Replies

8. UNIX for Dummies Questions & Answers

Matching and reporting near-similar lines in a file

Hi, I have a file with the lines as below: C_10_A05_T7 C_10_A06_SP6 C_10_B05_SP6 C_10_B05_T7 C_10_B01_SP6 C_10_B01_T7 C_12_G07_SP6 C_12_G11_SP6 C_12_G11_T7 C_2_H18_T7 C_2_I02_SP6 C_2_I02_T7 C_2_I13_SP6 C_2_I17_SP6 The four segments of each line are connected by '_' symbols. I... (7 Replies)
Discussion started by: Fahmida
7 Replies

9. Shell Programming and Scripting

removing lines with similar values from file

Hello, got a file with this structure: 33274 171030 02/29/2012 37897 P_GEH 2012-02-29 10:31:26 33275 171049 02/29/2012 38132 P_GEH 2012-02-29 10:35:27 33276 171058 02/29/2012 38515 P_GEH 2012-02-29 10:43:26 33277 170748 02/29/2012 40685 P_KOM ... (3 Replies)
Discussion started by: krecik28
3 Replies

10. Shell Programming and Scripting

Reducing text file using similar lines

Hello, I am a java programmer but want to try unix for a purpose where I need to reduce a file using its first field.. Here is the sample data: admin;2;0;; admission;8;0;; aman;1;0;; caroline;0;4;; cook;0;4;; cook;2;0;; far;0;3;; far;1;5;; I am explaining the dataset first. There... (5 Replies)
Discussion started by: shekhar2010us
5 Replies
CREATE 
SCHEMA(7) PostgreSQL 9.2.7 Documentation CREATE SCHEMA(7) NAME
CREATE_SCHEMA - define a new schema SYNOPSIS
CREATE SCHEMA schema_name [ AUTHORIZATION user_name ] [ schema_element [ ... ] ] CREATE SCHEMA AUTHORIZATION user_name [ schema_element [ ... ] ] DESCRIPTION
CREATE SCHEMA enters a new schema into the current database. The schema name must be distinct from the name of any existing schema in the current database. A schema is essentially a namespace: it contains named objects (tables, data types, functions, and operators) whose names can duplicate those of other objects existing in other schemas. Named objects are accessed either by "qualifying" their names with the schema name as a prefix, or by setting a search path that includes the desired schema(s). A CREATE command specifying an unqualified object name creates the object in the current schema (the one at the front of the search path, which can be determined with the function current_schema). Optionally, CREATE SCHEMA can include subcommands to create objects within the new schema. The subcommands are treated essentially the same as separate commands issued after creating the schema, except that if the AUTHORIZATION clause is used, all the created objects will be owned by that user. PARAMETERS
schema_name The name of a schema to be created. If this is omitted, the user_name is used as the schema name. The name cannot begin with pg_, as such names are reserved for system schemas. user_name The role name of the user who will own the new schema. If omitted, defaults to the user executing the command. To create a schema owned by another role, you must be a direct or indirect member of that role, or be a superuser. schema_element An SQL statement defining an object to be created within the schema. Currently, only CREATE TABLE, CREATE VIEW, CREATE INDEX, CREATE SEQUENCE, CREATE TRIGGER and GRANT are accepted as clauses within CREATE SCHEMA. Other kinds of objects may be created in separate commands after the schema is created. NOTES
To create a schema, the invoking user must have the CREATE privilege for the current database. (Of course, superusers bypass this check.) EXAMPLES
Create a schema: CREATE SCHEMA myschema; Create a schema for user joe; the schema will also be named joe: CREATE SCHEMA AUTHORIZATION joe; Create a schema and create a table and view within it: CREATE SCHEMA hollywood CREATE TABLE films (title text, release date, awards text[]) CREATE VIEW winners AS SELECT title, release FROM films WHERE awards IS NOT NULL; Notice that the individual subcommands do not end with semicolons. The following is an equivalent way of accomplishing the same result: CREATE SCHEMA hollywood; CREATE TABLE hollywood.films (title text, release date, awards text[]); CREATE VIEW hollywood.winners AS SELECT title, release FROM hollywood.films WHERE awards IS NOT NULL; COMPATIBILITY
The SQL standard allows a DEFAULT CHARACTER SET clause in CREATE SCHEMA, as well as more subcommand types than are presently accepted by PostgreSQL. The SQL standard specifies that the subcommands in CREATE SCHEMA can appear in any order. The present PostgreSQL implementation does not handle all cases of forward references in subcommands; it might sometimes be necessary to reorder the subcommands in order to avoid forward references. According to the SQL standard, the owner of a schema always owns all objects within it. PostgreSQL allows schemas to contain objects owned by users other than the schema owner. This can happen only if the schema owner grants the CREATE privilege on his schema to someone else, or a superuser chooses to create objects in it. SEE ALSO
ALTER SCHEMA (ALTER_SCHEMA(7)), DROP SCHEMA (DROP_SCHEMA(7)) PostgreSQL 9.2.7 2014-02-17 CREATE SCHEMA(7)
All times are GMT -4. The time now is 12:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy