parse text or complex grep ?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers parse text or complex grep ?
# 1  
Old 04-23-2004
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  
Old 04-23-2004
Try..

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

Tested...

x_var aaaaaaaa
y_var bbbbbbbbb
# 3  
Old 04-23-2004
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  
Old 04-23-2004
thanks dudes, it was very helpful!!!
# 5  
Old 04-29-2004
Bug 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...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Complex Filter using grep, awk or sed

Hi, I'm not very familiar witrh sed or awk and hope the somebody can help me to solve my problem. I need to filter a text report using grep, sed or awk. I would like to cut out text lines with the pattern INFO and if exists the following lines of the pattern DETAILS. I need te keep the lines with... (4 Replies)
Discussion started by: Frankg
4 Replies

2. Shell Programming and Scripting

How to grep for a complex String?

Hi, I have a file hello.log which has the below entry ./logs/mymac/myserver.log:####<Jun 7, 2015 12:56:54 PM EDT> <myserver.my.bank.com> <mymac> < ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <1434640> <BEA-0900> <User user1 in security realm... (3 Replies)
Discussion started by: shifahim
3 Replies

3. Shell Programming and Scripting

Complex grep command

Hallo Team, I need your help and its rather urgent. I have a file with thousands of lines. Here is a sample below: Sample1.txt BW235045560121114833444044@196.35.130.5 BW235106757121114-574455394@196.35.130.5 BW2349514941211141077771352@196.35.130.5... (5 Replies)
Discussion started by: kekanap
5 Replies

4. Shell Programming and Scripting

Complex text parsing with speed/performance problem (awk solution?)

I have 1.6 GB (and growing) of files with needed data between the 11th and 34th line (inclusive) of the second column of comma delimited files. There is also a lot of stray white space in the file that needs to be trimmed. They have DOS-like end of lines. I need to transpose the 11th through... (13 Replies)
Discussion started by: Michael Stora
13 Replies

5. Shell Programming and Scripting

Music Playlist parse/grep

Hi. Please help with a single line bash that will match field 3, and field 2 , if not then echo "Not Found". Original Music List name; Musiclists.m3u Format: \Music\The Rolling Stones - Angel.mp3 \Music\Maroon 5\Moves Like Jagger.mp3 Make a groomed playlist variable... $... (0 Replies)
Discussion started by: DSommers
0 Replies

6. Shell Programming and Scripting

Grep/Parse a .xml file

I have a .xml file similar to the following: <Column> <Name>FIELD1</Name> <Title>CO.</Title> </Column> <Column> <Name>FIELD2</Name> <EditField>TextBox</EditField> <ColumnSpan0>4</ColumnSpan0> <Title>NORMAL</Title> ... (12 Replies)
Discussion started by: jl487
12 Replies

7. Shell Programming and Scripting

Difficult problem: Complex text file manipulation in bash script.

I don't know if this is a big issue or not, but I'm having difficulties. I apoligize for the upcoming essay :o. I'm writing a script, similar to a paint program that edits images, but in the form of ANSI block characters. The program so far is working. I managed to save the image into a file,... (14 Replies)
Discussion started by: tinman47
14 Replies

8. Shell Programming and Scripting

Replacing text between Tags, with output from a complex command

The Problem I have n files all named "conf.cfg", each of which contain a line that reads: "MyVar=XXX", where XXX can be any value. I have a second file called report.xml, that might read: <Reports> <Report>Report1</Report> <Report>Report2</Report> <Report>Report3</Report> </Reports> I... (1 Reply)
Discussion started by: Flang
1 Replies

9. Shell Programming and Scripting

Complex find grep or sed command

Haven't worked in bash for ages. did a good bit of shell scripting in regular sh, but have forgotten most of it. I have several thousand php files that now include the following line at the end of the file. There is no LF or CR/LF before it begins, it is just concatenated to the final line of... (3 Replies)
Discussion started by: sjburden
3 Replies

10. Shell Programming and Scripting

complex grep command

hi all i have file call "list.log" which contains like this 00300 000024501043846 0 00300 000034531322871 0 00600 000000489100734 0 and so on .. the file goes like this:(example first row) from position 1-5 the lider number(300),position 7-21 id... (0 Replies)
Discussion started by: naamas03
0 Replies
Login or Register to Ask a Question