Sponsored Content
Top Forums Shell Programming and Scripting Insert a text from a specific row into a specific column using SED or AWK Post 302333539 by durden_tyler on Monday 13th of July 2009 10:23:04 AM
Old 07-13-2009
Code:
$
$ cat data.txt
DEVICE STATUS INFORMATION FOR LOCATION 1:
OPER  STATES:  Disabled  E:Enabled   B:Busy
ADMIN STATES:  L:Locked    U:Unlocked  E:Equipped  S:Shutdown
                                              Last Transition Related
Device        State Reason                    dd/mm  hh:mm:ss Function
------------- ----- ------------------------- --------------- -------------
DRI 0 0 0     B-U   NO REASON                 05/07  02:28:27 RTF 0 0 0
DRI 0 1 0     B-U   NO REASON                 26/05  08:16:33 RTF 0 1 0
DRI 1 0 0     B-U   NO REASON                 05/07  02:28:27 RTF 1 0 0
DRI 1 1 0     B-U   NO REASON                 26/05  08:16:33 RTF 1 1 0
DRI 2 0 0     B-U   NO REASON                 05/07  02:28:27 RTF 2 0 0
DRI 2 1 0     B-U   NO REASON                 26/05  08:16:33 RTF 2 1 0
 
DEVICE STATUS INFORMATION FOR LOCATION 2:
OPER  STATES:  Disabled  E:Enabled   B:Busy
ADMIN STATES:  L:Locked    U:Unlocked  E:Equipped  S:Shutdown
                                              Last Transition Related
Device        State Reason                    dd/mm  hh:mm:ss Function
------------- ----- ------------------------- --------------- -------------
DRI 0 0 0     B-U   NO REASON                 05/07  02:29:16 RTF 0 0 0
DRI 0 1 0     B-U   NO REASON                 11/06  19:45:56 RTF 0 1 0
DRI 1 0 0     B-U   NO REASON                 05/07  02:29:16 RTF 1 0 0
DRI 1 1 0     B-U   NO REASON                 11/06  19:46:08 RTF 1 1 0
DRI 2 0 0     B-U   NO REASON                 05/07  02:29:16 RTF 2 0 0
 
DEVICE STATUS INFORMATION FOR LOCATION 3:
OPER  STATES:  Disabled  E:Enabled   B:Busy
ADMIN STATES:  L:Locked    U:Unlocked  E:Equipped  S:Shutdown
                                              Last Transition Related
Device        State Reason                    dd/mm  hh:mm:ss Function
------------- ----- ------------------------- --------------- -------------
DRI 0 0 0     B-U   NO REASON                 04/07  00:53:51 RTF 0 0 0
DRI 1 0 0     B-U   NO REASON                 04/07  00:53:51 RTF 1 0 0
DRI 1 1 0     B-U   NO REASON                 23/06  02:51:24 RTF 1 1 0
DRI 2 0 0     B-U   NO REASON                 04/07  00:53:51 RTF 2 0 0
DRI 2 1 0     B-U   NO REASON                 23/06  02:51:24 RTF 2 1 0
$
$ perl -ne '/DEVICE STATUS INFORMATION FOR (.*):/ and $x=$1; /^DRI/ and print "$x $_"' data.txt
LOCATION 1 DRI 0 0 0     B-U   NO REASON                 05/07  02:28:27 RTF 0 0 0
LOCATION 1 DRI 0 1 0     B-U   NO REASON                 26/05  08:16:33 RTF 0 1 0
LOCATION 1 DRI 1 0 0     B-U   NO REASON                 05/07  02:28:27 RTF 1 0 0
LOCATION 1 DRI 1 1 0     B-U   NO REASON                 26/05  08:16:33 RTF 1 1 0
LOCATION 1 DRI 2 0 0     B-U   NO REASON                 05/07  02:28:27 RTF 2 0 0
LOCATION 1 DRI 2 1 0     B-U   NO REASON                 26/05  08:16:33 RTF 2 1 0
LOCATION 2 DRI 0 0 0     B-U   NO REASON                 05/07  02:29:16 RTF 0 0 0
LOCATION 2 DRI 0 1 0     B-U   NO REASON                 11/06  19:45:56 RTF 0 1 0
LOCATION 2 DRI 1 0 0     B-U   NO REASON                 05/07  02:29:16 RTF 1 0 0
LOCATION 2 DRI 1 1 0     B-U   NO REASON                 11/06  19:46:08 RTF 1 1 0
LOCATION 2 DRI 2 0 0     B-U   NO REASON                 05/07  02:29:16 RTF 2 0 0
LOCATION 3 DRI 0 0 0     B-U   NO REASON                 04/07  00:53:51 RTF 0 0 0
LOCATION 3 DRI 1 0 0     B-U   NO REASON                 04/07  00:53:51 RTF 1 0 0
LOCATION 3 DRI 1 1 0     B-U   NO REASON                 23/06  02:51:24 RTF 1 1 0
LOCATION 3 DRI 2 0 0     B-U   NO REASON                 04/07  00:53:51 RTF 2 0 0
LOCATION 3 DRI 2 1 0     B-U   NO REASON                 23/06  02:51:24 RTF 2 1 0
$
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can sed be used to insert data at specific column?

I'm trying to use sed to insert data at a specific column, let's say my data looks like this: 0553 1828 0552 1829 0550 1829 0549 1830 0548 1831 what I want is this: timein 0553 timeout 1828 timein 0552 timeout 1829 timein 0550 timeout 1829 timein 0549 timeout 1830 timein 0548... (5 Replies)
Discussion started by: mswartz
5 Replies

2. UNIX for Dummies Questions & Answers

AWK Command to find text in specific column

I'm new to scripting and would appreciate any help. I have a list of over 20 words in File1 that I need to find in columns 10-15 of File2. I need the entire row of File2 that the File1 list matches. I originally used a grep command which works, but provides File1 results that can be found... (3 Replies)
Discussion started by: Chillin
3 Replies

3. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

4. UNIX for Dummies Questions & Answers

Use sed to replace but only in a specific column of the text file

Hi, I would like to use sed to replace NA to x ('s/NA/x/g'), but only in the 5th column of the space delimited text file, nowhere else. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

5. UNIX for Dummies Questions & Answers

awk: convert column to row in a specific way

Hi all! I have this kind of output: a1|b1|c1|d1|e1 a2|b2|c2 a3|b3|c3|d3 I would like to transpose columns d and e (when they exist) in column c, and under the row where they come from. Then copying the beginning of the row. In order to obtain: a1|b1|c1 a1|b1|d1 a1|b1|e1 a2|b2|c2... (1 Reply)
Discussion started by: lucasvs
1 Replies

6. Shell Programming and Scripting

Print unique names in each row of a specific column using awk

Is it possible to remove redundant names in the 4th column? input cqWE 100 200 singapore;singapore AZO 300 400 brazil;america;germany;ireland;germany .... .... output cqWE 100 200 singapore AZO 300 400 brazil;america;germany;ireland (4 Replies)
Discussion started by: quincyjones
4 Replies

7. Shell Programming and Scripting

Insert text into specific column

I have the following data: Dec 24 11:31:10 0000008b 9911662486 Answered Price SGD 0.003 PERIOD: 0 m 6 s Dec 24 11:21:42 00000086 9911662486 Answered Price SGD 0.001 PERIOD: 0 m 2 s Dec 20 15:34:28 00000004 9911662486 Answered Price SGD 0.007 PERIOD: 0 m 12 s Dec 20 18:42:30 0000017b... (6 Replies)
Discussion started by: alegnagrp
6 Replies

8. Shell Programming and Scripting

awk or sed to find specific column from different files

Hi everybody, I have a folder with many files: Files with 8 columns: X 123 A B C D E F And files with 7 columns: X1234 A B C D E F I am trying to find a way to extract the 5th column when the files have eight columns, or the 4th column when the files have... (3 Replies)
Discussion started by: Tzole
3 Replies

9. Shell Programming and Scripting

sed or awk to remove specific column to one range

I need to remove specific column to one range source file 3 1 000123456 2 2 000123569 3 3 000123564 12 000123156 15 000125648 128 000125648 Output required 3 000123456 2 000123569 3 000123564 12 000123156 15 000125648 128 000125648 (6 Replies)
Discussion started by: ranjancom2000
6 Replies

10. Shell Programming and Scripting

Using awk to change a specific column and in a specific row

I am trying to change the number in bold to 2400 01,000300032,193631306,190619,0640,1,80,,2/ 02,193631306,000300032,1,190618,0640,CAD,2/ I'm not sure if sed or awk is the answer. I was going to use sed and do a character count up to that point, but that column directly before 0640 might... (8 Replies)
Discussion started by: juggernautjoee
8 Replies
DBLINK_BUILD_SQL_DELETE(3)				  PostgreSQL 9.2.7 Documentation				DBLINK_BUILD_SQL_DELETE(3)

NAME
dblink_build_sql_delete - builds a DELETE statement using supplied values for primary key field values SYNOPSIS
dblink_build_sql_delete(text relname, int2vector primary_key_attnums, integer num_primary_key_atts, text[] tgt_pk_att_vals_array) returns text DESCRIPTION
dblink_build_sql_delete can be useful in doing selective replication of a local table to a remote database. It builds a SQL DELETE command that will delete the row with the given primary key values. ARGUMENTS
relname Name of a local relation, for example foo or myschema.mytab. Include double quotes if the name is mixed-case or contains special characters, for example "FooBar"; without quotes, the string will be folded to lower case. primary_key_attnums Attribute numbers (1-based) of the primary key fields, for example 1 2. num_primary_key_atts The number of primary key fields. tgt_pk_att_vals_array Values of the primary key fields to be used in the resulting DELETE command. Each field is represented in text form. RETURN VALUE
Returns the requested SQL statement as text. NOTES
As of PostgreSQL 9.0, the attribute numbers in primary_key_attnums are interpreted as logical column numbers, corresponding to the column's position in SELECT * FROM relname. Previous versions interpreted the numbers as physical column positions. There is a difference if any column(s) to the left of the indicated column have been dropped during the lifetime of the table. EXAMPLES
SELECT dblink_build_sql_delete('"MyFoo"', '1 2', 2, '{"1", "b"}'); dblink_build_sql_delete --------------------------------------------- DELETE FROM "MyFoo" WHERE f1='1' AND f2='b' (1 row) PostgreSQL 9.2.7 2014-02-17 DBLINK_BUILD_SQL_DELETE(3)
All times are GMT -4. The time now is 07:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy