Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Specific Parameters 1

Status
Not open for further replies.

dvknn

IS-IT--Management
Mar 11, 2003
94
US
Hi..I have a file which looks like this:

2003.11.13,(h p computer) - FILTER: 1
2003.11.13,(marketing tool) - FILTER: 1
2003.11.13,(market tool) - FILTER: 1
2003.11.13,(market item) - FILTER: 1
2003.11.13,(avionics) - FILTER: 4
2003.11.13,(Proofs (printing)) - FILTER: 1
2003.11.13,(heart medication) - FILTER: 2
2003.11.13,(FOLIOS) - FILTER: 1
2003.11.13,(molded plastic) - FILTER: 1
2003.11.13,(PORTFOLIOS) - FILTER: 1
2003.11.13,(paint equipment) - FILTER: 1
2003.11.13,(portfolios) - FILTER: 1

In my output, I should see the lines without the starting "(" and ending ")". So, my file should look like :

2003.11.13,h p computer - FILTER: 1
2003.11.13,marketing tool - FILTER: 1
2003.11.13,market tool - FILTER: 1
2003.11.13,market item - FILTER: 1
2003.11.13,avionics - FILTER: 4
2003.11.13,Proofs (printing) - FILTER: 1
2003.11.13,heart medication - FILTER: 2
2003.11.13,FOLIOS - FILTER: 1
2003.11.13,molded plastic - FILTER: 1
2003.11.13,PORTFOLIOS - FILTER: 1
2003.11.13,paint equipment - FILTER: 1
2003.11.13,portfolios - FILTER: 1

I have tried an awk..but, my awk results show me without "("..so, for
2003.11.13,Proofs (printing) - FILTER: 1, I see my output as 2003.11.13,Proofs printing)) - FILTER: 1

Can anybody help me please?
Thanks
 
Try this
Code:
#!/bin/awk -f

{
  match($0,"\\(.*\\)")
  left = substr($0,1,RSTART-1)
  mid  = substr($0,RSTART,RLENGTH)
  right= substr($0,RSTART+RLENGTH)
  sub("^\\(","",mid)
  sub("\\)$","",mid)
  print left mid right
}

--
 
Try something like this:
Code:
sed -e 's!(!!;s!\(.*\))!\1!' <input >output

Hope This Help
PH.
 
I have this 'awk' script.

BEGIN {
FS=&quot;[()]&quot;
OFS=&quot;,&quot;
}
{
split($1, a, &quot; &quot;);
print a[1],$2
}

the line
2003.11.13,(Proofs (printing)) - FILTER: 1

comes out
2003.11.13,Proofs printing

but, I want to get
2003.11.13,Proofs (printing) - FILTER: 1

Is this possible?

 
dvknn, have you tried the sed script I posted ?
 
Sorry PHV, Could you please explain the script before I try...it will make more sense if I understand it..
 
Code:
>sed -e 's!(!!;s!\(.*\))!\1!' <input >output 
s!(!!          Suppress the 1st &quot;(&quot;
s!\(.*\))!\1!  Suppress the last &quot;)&quot;
 
Do I need to have the &quot;<&quot; and &quot;>&quot; in the command?

 
I got it..

But still not what I want...Let me try some other thing and get back with you guys.
 
Don't understand why still not what you want.
Tested on my machine with your input example, got your output example. What' wrong ?
 
Sorry PHV...your script works..Let me tell you the story..

The file that I have looks like this:

2003.11.13 15:59:08 [Thread-65761] toa1.sac.fedex.com [5] gemstone DocumentDeterminationServer.keywordSearch NO KEYWORD MATCH: avionics - FILTER: 4
2003.11.13 15:59:34 [Thread-65801] toa1.sac.fedex.com [5] gemstone DocumentDeterminationServer.keywordSearch NO KEYWORD MATCH: Proofs (printing) - FILTER: 1
2003.11.13 15:59:34 [Thread-65801] toa1.sac.fedex.com [5] gemstone DocumentDeterminationServer.keywordSearch NO KEYWORD MATCH: Proofs (printing) - FILTER: 1
2003.11.13 16:00:56 [Thread-65863] toa1.sac.fedex.com [5] gemstone DocumentDeterminationServer.keywordSearch NO KEYWORD MATCH: heart medication - FILTER: 2

now, out of this how can I get

2003.11.13,avionics - FILTER: 4
2003.11.13,Proofs (printing) - FILTER: 1
2003.11.13,Proofs (printing) - FILTER: 1
2003.11.13,heart medication - FILTER: 2

thanks
 
Try this:
Code:
sed -e 's! .*MATCH:!,!'

Hope This Help
PH.
 
sed -e 's! .*MATCH:!,!' </path/to/input >/path/to/output
 
I got it....everything LOOKS GOOD NOW....
Thanks for answering my questions so patiently..

 
Some good tips. But I'm struggling to get something working for my problem.

I'm trying to remove everything between the ( ) from the following line:
cisco 7206 (NPE200) processor (revision B) with 114688K/16384K bytes of memory.

The only part I need to see out the line is the &quot;114688K/16384K&quot; part. Easy to do if all lines are of the same length. Problem is some lines look like this :
cisco RSP4 (R5000) processor with 131072K/2072K bytes of memory.

The options I see, are to remove the () and anything inside them somehow and then awk '{print $5}' for example.
The other option is to somhow revers the word order and print the column needed.

I know somebody knows this ;-)

Thanks all.
 
That other option would be...

awk '{print $(NF-3)}' file1
 
Thanks :)

Many ways to kill the cat .. managed to find a command similar to the one you mantioned Ygor.

I take it NF means something like Near Field? -3 from 3rd last.

I tried awk -Fwith '{print $NF}' | awk '{print $1}' and was left with the entry I needed.

Thank you all .. another good tip for the memory banks.

 
Try something like this:
Code:
sed -e 's!.with !!;s! bytes.*!!'

Hope This Help
PH.
 
echo 'cisco RSP4 (R5000) processor with 131072K/2072K bytes of memory.' | nawk -F'(with)|(bytes)' '{print $2}'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top