awk script to get words which are not in a particula order


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk script to get words which are not in a particula order
# 1  
Old 03-27-2010
awk script to get words which are not in a particula order

Hi all,

I need a big help. I've a requirment which should be done in awk scripting only..
My requirment is:

In below file, there are some lines started with 'master replica:'.
i want to get the exact word in that line which should be before '@', and i've to create a file with these names line by line. Either the input file may contain multiple replicas or it may has only original replica.. But any of these both cases, it must contain the original replica..
Ex o/p:
replica1
replica2
original
*******************Sample File Contents*******************
replica "<replica1>"
2006-10-10T06:02:36+10 by Clearcase Admin Acct - xxxxxxx; xxxxxxx [xxxxxxx] (xxxxxxx@main_server)
"Replica for stm VOB /vobs/<vob_name>"
replica type: unfiltered
master replica: <replica1>@/vobs/<vob_name>
owner: vobadmin
group: xxxxxxxxx
host: "<replica_server1>"
identities: preserved
permissions: preserved
feature level: unknown
connectivity: connected
replica "<replica2>"
2006-10-10T06:02:36+10 by Clearcase Admin Acct - xxxxxxx; xxxxxxx [xxxxxxx] (xxxxxxx@main_server)
"Replica for stm VOB /vobs/<vob_name>"
replica type: unfiltered
master replica: <replica2>@/vobs/<vob_name>
owner: vobadmin
group: xxxxxxxxx
host: "<replica_server2>"
identities: preserved
permissions: preserved
feature level: unknown
connectivity: connected
replica "original"
2005-11-02T22:51:59+11 by ************* (***-**-*-@/**/*/*/*/)
"<Original_replica>"
replica type: unfiltered
master replica: original@/vobs/<vob_name>
request for mastership: enabled
owner: laserdev
group: xxxxxxxxx
host: "<main_server_alias>"
identities: preserved
permissions: preserved
feature level: 4
connectivity: connected
***************************************************
So It means that, the script should create a file with all replica names like in above mentioned example and it has to return (as an o/p) the host parameter of original replica.
For example, there is a replica with "original" name (see below for example), so under that original replica, there is a line which start with "host:", I want to get that <main_server_alias> name as a o/p of the script.
*****************example one*************
replica "original"
2005-11-02T22:51:59+11 by ************* (***-**-*-@/**/*/*/*/)
"<Original_replica>"
replica type: unfiltered
master replica: original@/vobs/<vob_name>
request for mastership: enabled
owner: laserdev
group: xxxxxxxxx
host: "<main_server_alias>" ------> I want to get this <main_server_alias> name as a o/p of the script
identities: preserved
permissions: preserved
feature level: 4
connectivity: connected
*************************************

Can anyone please help on this? It'll very helpful for me..
Thank you to everyone for providing great steps for my queries..
Please let me know for any queries/doubts on this...

Thanks in advance..
Regards,
Raghu
# 2  
Old 03-27-2010
Why only awk?Smilie
And not quite clear what you want but hope this helps...
Code:
awk -F":|@" '/master replica/{gsub("[ |<|>]","",$2);printf $2}/host/{gsub("[ |<|>]","",$2);printf "\t"$2"\n"}' infile

# 3  
Old 03-27-2010
Hi, thank you vm for your reply..

As per our comany policies, we have to use awk scripting only..
And the given command is giving some syntax errors, can you please help?

$ awk -F":|@" '/master replica/{gsub("[ |<|>]","",$2);printf $2}/host/{gsub("[ |<|>]","",$2);printf "\t"$2"\n"}' cctpl.log #This file is attached in this thread#
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
$


Actually i want to create a file with all replicas in the input file like below,
---------
replica1
replica2
...
..
..
original
---------
At any cost, the input file must have one 'original' replica..

And the script has to return a value (which is coloured in red below) as an o/p under this original replica..

*****************example one*************
replica "original"
2005-11-02T22:51:59+11 by ************* (***-**-*-@/**/*/*/*/)
"<Original_replica>"
replica type: unfiltered
master replica: original@/vobs/<vob_name>
request for mastership: enabled
owner: laserdev
group: xxxxxxxxx
host: "<main_server_alias>" ---> I want to get this <main_server_alias> name as a o/p of the script
identities: preserved
permissions: preserved
feature level: 4
connectivity: connected
*************************************

I hope, you are clear in my requirment now..
Thank you vm again for your help on this...
Please let me know for any queries on this..

Regards,
Raghu
# 4  
Old 03-27-2010
sorry.. attached the input file now...

Thanks in advance again..
# 5  
Old 03-27-2010
use nawk instead of awk...

Code:
nawk -F":|@" '/master replica/{gsub("[ |<|>]","",$2);printf $2}/host/{gsub("[ |<|>]","",$2);printf "\t"$2"\n"}' cctpl.log

# 6  
Old 03-27-2010
great thanks malcom...Smilie

It's working and i got my required o/p...

Thank you so much..
I've to learn awk soon, it's very powerful tool...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using awk add preffic to dynamic order

Source file portIndex: 75 portName: slot9 port11 c0:50:96:05:9f:f2:00:f2 c0:50:96:05:9f:f2:00:ea c0:50:96:05:9f:f2:01:13 c0:50:96:05:9f:f2:01:12 c0:50:96:05:9f:f2:01:0b c0:50:96:05:9f:f2:01:0a c0:50:96:05:9f:f2:01:03 ... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

2. Shell Programming and Scripting

How order a data matrix using awk?

is it possible to order the following row clusters from ascending to descending. thanx in advance input 1 2 4 0 1 2 4 0 3 3 3 3 1 5 1 0 1 5 1 0 6 0 0 0 5 1 1 1... (4 Replies)
Discussion started by: quincyjones
4 Replies

3. Shell Programming and Scripting

awk - Why does output order change?

I have this END section in an awk script: END { for (j in littlebin) { print (j, int(log(j)/log(2)) , littlebin) lbsum+=littlebin } for (i in bins) ... (6 Replies)
Discussion started by: treesloth
6 Replies

4. Shell Programming and Scripting

Putting values into order in a field using awk

Hi, I am using UBUNTU 12.04. I have a dataset as follows: Column#1 Column#2 Column#3 .... Column#50 1 154878 1 145145 2 189565 2 454121 ... (5 Replies)
Discussion started by: Homa
5 Replies

5. UNIX for Dummies Questions & Answers

Searching for multiple words on a line in any order issue

Hi again I have figured out how to be able to sort through lines in a file with multiple words in any order and display them using this command: cat file | grep -i $OPTION1 | grep -i $OPTION2 | grep -i $OPTION3 OPTION1 is 2008, OPTION2 is Mar, OPTION 3 is Tue Result: Tue Mar 25... (4 Replies)
Discussion started by: semaj
4 Replies

6. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

7. Shell Programming and Scripting

Keep lines with specific words up in an order

I hava a file with following data: number|CREDIT_ID|NULL date|SYS_CREATION_DATE|NULL varchar2|GGS_COMMIT_CHAR|NULL varchar2|GGS_OP_TYPE|NULL number|GGS_SCN|NULL| number|GGS_LOG_SEQ|NULL number|GGS_LOG_POS|NULL number|GGS_ORACREC_SCN|NULL varchar2|BATCH_ID|NULL char|GGS_IMAGE_TYPE|NULL ... (6 Replies)
Discussion started by: kolesunil
6 Replies

8. Shell Programming and Scripting

sed or awk to order a file

Hi - I have a file with lots of lines in that I need to order based on the number of commas! e.g the file looks something like :- cn=john,cn=users,cn=uk,dc=dot,dc=com cn=john,cn=users,dc=com cn=users,cn=groups,dc=com cn=john,cn=admins,cn=users,cn=uk,dc=dot,dc=com... (4 Replies)
Discussion started by: sniper57
4 Replies

9. Shell Programming and Scripting

compare strings, words in different order

Hi, Would anyone know how to compare two strings, and only throw an error if there were different words, not that the same words were in a different order? e.g "A B C" vs "B C A" ->OK "A B C" vs "A D C" -> BAD Thanks! (2 Replies)
Discussion started by: rebelbuttmunch
2 Replies

10. Shell Programming and Scripting

List number in decending order using AWK

Hi All, Can anyone show me how to list the below numbers in decending order? I have a code to find out whats the largest number though but can it be modified to in-corporate in function ? Thanks in advance Input: 20 30 10 40 50 Output: 50 40 30 20 (2 Replies)
Discussion started by: Raynon
2 Replies
Login or Register to Ask a Question