Select particular string using AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Select particular string using AWK
# 1  
Old 03-11-2009
Select particular string using AWK

Hi all,
i searched this forum for the awk help i needed but i couldnt get any thread matching to my problem,
My problem is
i have a file

file1 {
<Server CloneID="13k6equ4c" Name="EnterpriseServicesClone2">
<Server CloneID="13k6eqvi1" Name="EnterpriseServicesClone1">
<Server CloneID="13k6er1lu" Name="INTLEStatementClone1">
<Server CloneID="13k6er4id" Name="GlobalMRClone1">
<Server CloneID="13k6er6lg" ConnectTimeout="3" Name="GlobalUserManagementClone1">
<Server CloneID="13k6erbi4" ConnectTimeout="3" Name="USEStatementClone1">
<Server CloneID="13k6erd1h" ConnectTimeout="3" Name="USEStatementClone2">
<Server CloneID="13k6erfkj" Name="MYCAServicesClone2">
<Server CloneID="13k6erh8n" Name="MYCAServicesClone1">
<Server CloneID="13k6erk21" Name="DocGenClone1">
<Server CloneID="13k6ern9r" Name="OnlineDisputesClone1">
<Server CloneID="13k6erqb0" Name="TransferClone1">
<Server CloneID="13ta8bqd3" Name="BasicServicesClone2">
<Server CloneID="13tacbiag" Name="BasicServicesClone1">
<Server CloneID="13k6er95a" ConnectTimeout="3" Name="USAccountSummaryClone1">
<Server CloneID="13v8rg2qo" ConnectTimeout="3" Name="USAccountSummaryClone2">
}

Now my problem is i want output as:

EnterpriseServicesClone2
EnterpriseServicesClone1
INTLEStatementClone1
GlobalMRClone1
GlobalUserManagementClone1
USEStatementClone1
USEStatementClone2
MYCAServicesClone2
MYCAServicesClone1
DocGenClone1
OnlineDisputesClone1
TransferClone1
BasicServicesClone2
BasicServicesClone1
USAccountSummaryClone1
USAccountSummaryClone2


but when i am using command as
awk -F"Name" '{print $2}' | |awk -F"\"" '{print $2}'

i am not getting the proper output

The output is coming like this:

ame="EnterpriseServicesClone2
ame="EnterpriseServicesClone1
ame="I
ame="GlobalMRClone1
ame="GlobalUserManagementClone1
ame="USEStatementClone1
ame="USEStatementClone2
ame="MYCAServicesClone2
ame="MYCAServicesClone1
ame="DocGenClone1
ame="OnlineDisputesClone1
ame="TransferClone1
ame="BasicServicesClone2
ame="BasicServicesClone1
ame="USAccountSummaryClone1
ame="USAccountSummaryClone2


Can anybody help??

Thanks in advance..
# 2  
Old 03-11-2009
You don't need awk for this task:

Code:
sed -n 's/.*Name="\([^"]*\).*/\1/p' infile

# 3  
Old 03-11-2009
assuming the 'Name' appears at the tail end of the record/line:
Code:
nawk -F'"' '{print $(NF-1)}' myFile

# 4  
Old 03-11-2009
Code:
awk -F "\"" '/^<Server/ {print $(NF-1)}' infile


Last edited by zaxxon; 03-11-2009 at 12:33 PM.. Reason: optimization
# 5  
Old 03-12-2009
Code:
sed 's/^\(.*\)\(Name="\)\([^"]*\)\(".*\)/\3/' filename

# 6  
Old 05-14-2009
Hi all,
i have one more doubt with this sed

i have a line

Code:
"Instrumentation-MetricsThread:4 of 5" daemon prio=5 tid=0xfacf10 nid=0x39 waiting on monitor [0xba181000..0xba181a00]


here i need output as 0xfacf10 the value after tid=

But here i cannot use awk awk -F" " '{print $6}'
as this is just a sample and the position of this value tid=value may change to 3rd or 4th position.

Can anyone give sed code to just select value after tid= and nothing after that.

Thanks
# 7  
Old 05-14-2009
Quote:
Originally Posted by usha rao
...Can anyone give sed code to just select value after tid= and nothing after that...
Code:
$
$ echo "Instrumentation-MetricsThread:4 of 5" daemon prio=5 tid=0xfacf10 nid=0x39 waiting on monitor [0xba181000..0xba181a00] | sed 's/.*tid=\([^ ]*\) .*/\1/'
0xfacf10
$

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Query to SELECT only Column Names that Contain a Specific String?

Hey Guys, I'm using SQuirreL SQL v3.5 GUI to fetch some data that I need for something I'm working on. I'm also using the IBM Informix Driver (*Version 3.5) to connect to the Database. What I want to do, if it's even possible, is to show all COLUMNS if they contain the word "Email". So in... (2 Replies)
Discussion started by: mrm5102
2 Replies

2. UNIX for Dummies Questions & Answers

select and replace only those string which is followed by \tab

Hi I have a number of sequences and a string occurs a number of times in that sequence. How can I select and replace only those strings which are followed by \tab. for eg : my sequence looks like : string0 positive cd parent=string0 id =121 string0 string0 negative ef parent=... (2 Replies)
Discussion started by: sonia102
2 Replies

3. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

4. Shell Programming and Scripting

awk with fields select?

If i have a log file record.txt, with 10 fields - First field is datetime - 7th field is status - 8th filed is name - The last field (10th) is epoch time of the first field 02/17/2012 1:47 PM||||||In Use|chicken||1329515230 02/17/2012 2:53 PM||||||Available|chicken||1329519195 02/17/2012... (4 Replies)
Discussion started by: sabercats
4 Replies

5. Shell Programming and Scripting

How to select a single string

I am learning sed/awk. So, bear with me. I have successfully created a list (based on sed) which looks like: <cl:item href="clsysrev/XTT004/XTT05064.xml" productSubtitle="animals" unitStatus="today"IR"> <cl:item href="clsysrev/XTT007/XTT08581.xml" productSubtitle="humans"... (3 Replies)
Discussion started by: alonso_canada
3 Replies

6. Shell Programming and Scripting

how to test input variable is a string in a select loop

Okay -- I hope I ask this correctly. I'm working on my little shell script to write vendor names and aliases to files from user input. If a user choose to add to a file, he can do that as well. I'm using a select loop for this function to list all the possible files the user can choose from.... (7 Replies)
Discussion started by: Straitsfan
7 Replies

7. Shell Programming and Scripting

Select a specific part of the string and print it

Hi all, I have a string that looks like: #!/bin/sh options="arguments: --user=alpha --group=beta --prefix=/usr/share --proxy-path=/proxy --proxy-tmp=/tmp --conf-path=/etc" My goal is to transform the string into an array, then for each key, if it starts with "--proxy" to print the string... (2 Replies)
Discussion started by: TECK
2 Replies

8. Shell Programming and Scripting

How to select only the most frequent instances of a variable string in a file?

I've got a web access file that I want to grep (or awk or perl or whatever will work!) out the most frequent instances of unique IP entries. Meaning the file looks something like this: I'd like to run a sort or grep (or whatever) that will only select out the lines from IP's that had the... (7 Replies)
Discussion started by: kevinmccallum
7 Replies

9. Shell Programming and Scripting

How to select the path that contains a certain string from a certain file?

Hi, I am new to this world of shell programming. I am facing a problem that is : I have directory which has many sub directories at different depth. say A/B/C/files A/B/files A/B/C/D/files In this directory structure there exists a file called ".project" in some of the sub... (2 Replies)
Discussion started by: bhaskar_m
2 Replies

10. Shell Programming and Scripting

SQL Select and awk

Dear All , I have file1.txt contain values like the following: ---------- 23 24 25 and I have shell script which has the following : more file1.txt | awk '{print "select 'DUMP',CODE1||'|'||CODE2||'|'||CODE3 from CODE where CODE1='" $1 "';"}' > file2.sql all I need is to have the... (6 Replies)
Discussion started by: habuzahra
6 Replies
Login or Register to Ask a Question