Sponsored Content
Top Forums Shell Programming and Scripting --Parsing out strings for repeating delimiters for everyline Post 303040129 by gilgamesh on Wednesday 23rd of October 2019 05:19:13 PM
Old 10-23-2019
--Parsing out strings for repeating delimiters for everyline

Hello:

I have some text output, on SunOS 5.11 platform using KSH:

Quote:
QREMOTE(BOS.FOS.T.CDG.MEDGTOC.01) CLUSTER(CLENTT1) DEFBIND(NOTFIXED) DEFPSIST(YES) DESCR(Cargo dangerous goods queue) RQMNAME(CLCRGT1) RNAME(BOS.FOS.T.CDG.MEDGTOC.01) XMITQ( )
QREMOTE(CLFOST1) CLUSTER(CLENTT1) DEFBIND(NOTFIXED) DEFPSIST(YES) DESCR(Qmgr Alias for CLFOST1 Cluster) XMITQ( )
QREMOTE(RPT.PSS.T.VILS.ODY.01) CLUSTER(CLENTT1) DEFPSIST(YES) DESCR(PSS MSGS TO VILS ODYSSEY) RQMNAME(CLITAT1) RNAME(RPT.PSS.T.VILS.ODY.01) XMITQ( )
I am trying to parse out each string within the () for each line.

I tried, as example:
Code:
perl -lanF"[()']" -e 'print "$F[1] $F[2] $F[3] $F[4] $F[5] $F[6]"'

But for some reason, the output gets all garbled after the the first fields.
Guess I can try the following but it is very messy, as I would have to do that for each Descriptor before the first (.
The number of fields can change dynamically..

Another example:

Code:
cat $FILE | |nawk -FDESCR '{print $2}'| perl -lanF"[()]" -e 'print $F[1]'

So the desired output woul be:

Quote:
BOS.FOS.T.CDG.MEDGTOC.01 CLENTT1 NOTFIXED) YES Cargo dangerous goods queue CLCRGT1 BOS.FOS.T.CDG.MEDGTOC.01
CLFOST1 CLENTT1 NOTFIXED YES Qmgr Alias for CLFOST1 Cluster
RPT.PSS.T.VILS.ODY.01 CLENTT1 YES PSS MSGS TO VILS ODYSSEY CLITAT1 RPT.PSS.T.VILS.ODY.01
Not sure what else I can try.

Thanking you for any advice !!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

parsing with multible delimiters

I have data that looks like this aaa!bbb!ccc/ddd/eee It is not fixed format. I need to parse ddd into a var in order to decide if I want to process that row. If I do I need to put ccc and bbb into vars to process it. I need to do this during a while loop one record at a time. Any... (11 Replies)
Discussion started by: gillbates
11 Replies

2. Shell Programming and Scripting

cut columns in everyline

Is there a betterway to cut certain columns in everyline based on positions. Basically, I have a largefile and eachline is of 1000 characters and I need to cut the characters 17-30, 750-775, 776-779, 780-805 while do fptr=`cat $tempfile | head -$i | tail -1` ... (4 Replies)
Discussion started by: gunaah
4 Replies

3. Shell Programming and Scripting

Parsing file to match strings

I have a file with the following format 12g data/datasets/cct 8g data/dataset/cct 10 g data/two 5g data/something_different 10g something_different 5g data/two is there a way to loop through this... (1 Reply)
Discussion started by: yawalias
1 Replies

4. Shell Programming and Scripting

Awk new datetime everyline

Hi, I'm using awk in HP-UX machine which does not support systime(), strftime(). So to get the date time I was using : seq 1 100000 | awk ' "date +%Y%m%d%H%M%s" | getline curtime; print curtime }' However the above code gets the date only once, next time it is not updated. For... (2 Replies)
Discussion started by: Random_Net
2 Replies

5. Shell Programming and Scripting

Parsing Strings

Hello All, I am new to shell scripting and programming. I am looking for a guide on how I can parse specific information from a plain text file with thousands of lines. Specifically I need to parse an email address from each line. The line looks something like this:... (9 Replies)
Discussion started by: solvdsystems
9 Replies

6. Shell Programming and Scripting

Extract strings within XML file between different delimiters

Good afternoon! I have an XML file from which I want to extract only certain elements contained within each line. The problem is that the format of each line is not exactly the same (though similiar). For example, oa_var will be in each line, however, there may be no value or other... (3 Replies)
Discussion started by: bab@faa
3 Replies

7. UNIX for Dummies Questions & Answers

Adding variables to repeating strings

Hello, I want to add a letter to the end of a string if it repeats in a column. so if I have a file like this: DOG001 DOG0023 DOG004 DOG001 DOG0023 DOG001 the output should look like this: DOG001-a DOG0023-a DOG004 DOG001-b (15 Replies)
Discussion started by: verse123
15 Replies

8. Shell Programming and Scripting

How to append server name to everyline?

I am executing df -mP to see the disk utilization. I would like to append servername also to each and every line. df -mP | awk '{ print $1","$2","$3","$4","$5","$6 }' trying to add something like this df -mP | awk '{ print $1","$2","$3","$4","$5","$6","$hostname }' ... (1 Reply)
Discussion started by: lazydev
1 Replies

9. Shell Programming and Scripting

Script to rename the repeating strings

All, I have a sample text like below. Key (Header) Key1 ABC Key2 ABC Key3 ABC ABC Key4 ABC Key5 ABC ABC ABC Required Output Key (Header) Key1 (2 Replies)
Discussion started by: ks_reddy
2 Replies

10. Programming

Segfault When Parsing Delimiters In C

Another project, another bump in the road and another chance to learn. I've been trying to open gzipped files and parse data from them and hit a snag. I have data in gzips with a place followed by an ip or ip range sort of like this: Some place:x.x.x.x-x.x.x.x I was able to modify some code... (6 Replies)
Discussion started by: Azrael
6 Replies
CLUSTER(7)							   SQL Commands 							CLUSTER(7)

NAME
CLUSTER - cluster a table according to an index SYNOPSIS
CLUSTER [VERBOSE] tablename [ USING indexname ] CLUSTER [VERBOSE] DESCRIPTION
CLUSTER instructs PostgreSQL to cluster the table specified by tablename based on the index specified by indexname. The index must already have been defined on tablename. When a table is clustered, it is physically reordered based on the index information. Clustering is a one-time operation: when the table is subsequently updated, the changes are not clustered. That is, no attempt is made to store new or updated rows according to their index order. (If one wishes, one can periodically recluster by issuing the command again. Also, setting the table's FILLFACTOR storage parameter to less than 100% can aid in preserving cluster ordering during updates, since updated rows are preferentially kept on the same page.) When a table is clustered, PostgreSQL remembers which index it was clustered by. The form CLUSTER tablename reclusters the table using the same index as before. CLUSTER without any parameter reclusters all the previously-clustered tables in the current database that the calling user owns, or all such tables if called by a superuser. This form of CLUSTER cannot be executed inside a transaction block. When a table is being clustered, an ACCESS EXCLUSIVE lock is acquired on it. This prevents any other database operations (both reads and writes) from operating on the table until the CLUSTER is finished. PARAMETERS
tablename The name (possibly schema-qualified) of a table. indexname The name of an index. VERBOSE Prints a progress report as each table is clustered. NOTES
In cases where you are accessing single rows randomly within a table, the actual order of the data in the table is unimportant. However, if you tend to access some data more than others, and there is an index that groups them together, you will benefit from using CLUSTER. If you are requesting a range of indexed values from a table, or a single indexed value that has multiple rows that match, CLUSTER will help because once the index identifies the table page for the first row that matches, all other rows that match are probably already on the same table page, and so you save disk accesses and speed up the query. During the cluster operation, a temporary copy of the table is created that contains the table data in the index order. Temporary copies of each index on the table are created as well. Therefore, you need free space on disk at least equal to the sum of the table size and the index sizes. Because CLUSTER remembers the clustering information, one can cluster the tables one wants clustered manually the first time, and setup a timed event similar to VACUUM so that the tables are periodically reclustered. Because the planner records statistics about the ordering of tables, it is advisable to run ANALYZE [analyze(7)] on the newly clustered ta- ble. Otherwise, the planner might make poor choices of query plans. There is another way to cluster data. The CLUSTER command reorders the original table by scanning it using the index you specify. This can be slow on large tables because the rows are fetched from the table in index order, and if the table is disordered, the entries are on ran- dom pages, so there is one disk page retrieved for every row moved. (PostgreSQL has a cache, but the majority of a big table will not fit in the cache.) The other way to cluster a table is to use: CREATE TABLE newtable AS SELECT * FROM table ORDER BY columnlist; which uses the PostgreSQL sorting code to produce the desired order; this is usually much faster than an index scan for disordered data. Then you drop the old table, use ALTER TABLE ... RENAME to rename newtable to the old name, and recreate the table's indexes. The big dis- advantage of this approach is that it does not preserve OIDs, constraints, foreign key relationships, granted privileges, and other ancil- lary properties of the table -- all such items must be manually recreated. Another disadvantage is that this way requires a sort temporary file about the same size as the table itself, so peak disk usage is about three times the table size instead of twice the table size. EXAMPLES
Cluster the table employees on the basis of its index employees_ind: CLUSTER employees USING employees_ind; Cluster the employees table using the same index that was used before: CLUSTER employees; Cluster all tables in the database that have previously been clustered: CLUSTER; COMPATIBILITY
There is no CLUSTER statement in the SQL standard. The syntax CLUSTER indexname ON tablename is also supported for compatibility with pre-8.3 PostgreSQL versions. SEE ALSO
clusterdb [clusterdb(1)] SQL - Language Statements 2010-05-14 CLUSTER(7)
All times are GMT -4. The time now is 08:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy