The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Complex find grep or sed command sjburden Shell Programming and Scripting 3 05-31-2008 10:45 PM
parse through one text file and output many sophiadun UNIX for Dummies Questions & Answers 14 02-20-2008 06:08 AM
complex grep command naamas03 Shell Programming and Scripting 0 11-21-2007 04:59 AM
parse text file craggm Shell Programming and Scripting 9 02-27-2007 02:13 AM
parse text file klick81 Shell Programming and Scripting 3 12-18-2006 12:04 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-23-2004
jacost jacost is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 4
parse text or complex grep ?

I have the following file (records from db) and I need to retrieve in another file only two variables and their values. I have a command but works only for one value.
grep ^mob: R25-subs.ldi | sed 's/mob: //' | sort | uniq >text_output

Can someone please help me?
dn: cn=30693xxxxxxx,ou=sub,o=company
mob: x_var
pref: aaaaaaaa
sn: 30693xxxxxxxxxxx
userpassword: xxxxxxxxxx
allowmt: true
searchon: mms3069xxxxxxxx
searchon: mars30693xxxxxxx
allowmo: true
objectclass: xxxx
objectclass: xxxx
objectclass: xxxx
objectclass: xxxx
objectclass: xxxx
objectclass: xxxx
uid: 30693xxxxxx
cn: 30693xxxxxx
community: xxxxxx
orclguid: xxxxxxxxxxxxxxxxxxxx
creatorsname: cn=xxxxxxxx
modifiersname: cn=xxxxxxxx
createtimestamp: 2003xxxxxxxx
modifytimestamp: 2003xxxxxxxx

dn: cn=30693xxxxxxxx,ou=subscribers,o=company
mob: y_var
sn: 30693xxxxxxx
userpassword: xxxxxxxxxxxx
allowmt: true
searchon: mms30693xxxxxxx
searchon: mars3069xxxxxxx
allowmo: true
objectclass: xxxxx
objectclass: xxxxx
objectclass: xxxxx
objectclass: xxxxx
objectclass: xxxxx
objectclass: xxxxx
uid: 30693xxxxxx
cn: 30693xxxxxx
community: xxxxxx
orclguid: xxxxxxxxxxxxxxxxxxxxxxxxxx
creatorsname: cn=xxxxxxx
modifiersname: cn=xxxxxxx
createtimestamp: 20030212073811
modifytimestamp: 20040309041005
pref: bbbbbbbbb

...etc
How can I have an text output from the above block as:
x_var aaaaaaa
y_var bbbbbbb

or something like that
??????
  #2 (permalink)  
Old 04-23-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Try..

awk '
/^mob/ { m = $2 }
/^pref/ { print m, $2 }
' infile

Tested...

x_var aaaaaaaa
y_var bbbbbbbbb
  #3 (permalink)  
Old 04-23-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Or try using various utilities to get what you want...

$ egrep '^mob|^pref' infile
mob: x_var
pref: aaaaaaaa
mob: y_var
pref: bbbbbbbbb
$ egrep '^mob|^pref' infile | cut -d' ' -f2
x_var
aaaaaaaa
y_var
bbbbbbbbb
$ egrep '^mob|^pref' infile | cut -d' ' -f2 | paste -d' ' - -
x_var aaaaaaaa
y_var bbbbbbbbb
  #4 (permalink)  
Old 04-23-2004
jacost jacost is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 4
thanks dudes, it was very helpful!!!
  #5 (permalink)  
Old 04-29-2004
jacost jacost is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 4
Smile My version::

I did the following:
egrep 'mob:|pref:' filename

the only problem (minor) was that there was an output like difficult to follow like
mob=xxxx
pref=yyyy
mob=xxxx
pref=yyyy...

Anyway now I 'll try your ways...
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0