Regular expressions output is whole line


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Regular expressions output is whole line
# 1  
Old 03-27-2011
Regular expressions output is whole line

Hi,
I am newbie in shell programming and I need some help.

I had some data and I format it in a file like
Code:
dn: uid=aaaaa, dc=exmple, dc=com
cn: bbbb cccc
sn: cccc
telephoneNumber:+30-6543-123456

I have to extract the information aaaaa , bbbb, cccc and the phone number
using awk expressions

I am trying regular expressions like
Code:
awk '/dn: uid=[a-zA-Z]/ { print }' 1.txt

but the output is the whole line (not only the username)

can I save this info to arrays like usernames[] , firstnames[], lastnames[]

because I want to do something else later.

Thanks a lot for your help

Last edited by vgersh99; 03-27-2011 at 12:34 PM.. Reason: code tags, please!
# 2  
Old 03-27-2011
Code:
$ cat mytst
dn: uid=aaaaa, dc=exmple, dc=com
cn: bbbb cccc
sn: cccc
telephoneNumber:+30-6543-123456

$ awk -F"[ :=,]" '/^d/{x=4}/^[cs]n/{x=3}/^tel/{x=2}x{print $x;x=y}' mytst
aaaaa
bbbb
cccc
+30-6543-123456
$

This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 03-27-2011
Code:
nawk -F'[=,: ]' '{print /uid=/?$4:(/^telephoneN/)?$2:$3}' myFile

This User Gave Thanks to vgersh99 For This Post:
# 4  
Old 03-27-2011
thanks a lot
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

What is the difference between single line mode and multiline mode in Regular expressions?

Hi All, Can please let me know what is the difference between the single line mode and multi line mode in regular expresions? Thanks, Chidhambaram B (3 Replies)
Discussion started by: chidhu.anu
3 Replies

2. Shell Programming and Scripting

Regular Expressions

Hi Ilove unix and alwyas trying to to learn unix,but i am weak in using regular expressions.can you please give me a littel brief discription that how can i understand them and how to use .your response could lead a great hand in my unix love. (1 Reply)
Discussion started by: manoj attri
1 Replies

3. Shell Programming and Scripting

How to grep using a line break in regular expressions?

Hi, I have a file as below, {#### if file then file else file } print file i need to fine the count of all the pattern - file, inside the { } i'm using a grep command as grep -c \{'*file*'\} fake.sh\ It doesn't gives me any result, i think the problem here is the... (5 Replies)
Discussion started by: divak
5 Replies

4. Shell Programming and Scripting

Regular Expressions

what elements does " /^/ " match? I did the test which indicates that it matches single lowercase character like 'a','b' etc. and '1','2' etc. But I really confused with that. Because, "/^abc/" matches strings like "abcedf" or "abcddddee". So, what does caret ^ really mean? Any response... (2 Replies)
Discussion started by: DavidHe
2 Replies

5. Homework & Coursework Questions

Regular Expressions as command line paramteters

Use and complete the template provided. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: We have to write a program that uses wget to get pages of a URL and search them for a pattern. the command for the script should will look like this... (5 Replies)
Discussion started by: njmiano
5 Replies

6. UNIX for Advanced & Expert Users

Regular Expressions

Hi, below is a piece of code written by my predecessor at work. I'm kind of a newbie and am trying to figure out all the regular expressions in this piece of code. It is really a tough time for me to figure out all the regular expressions. Please shed some light on the regular expressions... (3 Replies)
Discussion started by: ramky79
3 Replies

7. UNIX for Dummies Questions & Answers

regular expressions

how to find for a file whose name has all characters in uppercase after 'project'? I tried this: find . -name 'project**.pdf' ./projectABC.pdf ./projectABC123.pdf I want only ./projectABC.pdf What is the regular expression that correponds to "all characters are capital"? thanks (8 Replies)
Discussion started by: melanie_pfefer
8 Replies

8. Shell Programming and Scripting

regular expressions

Hello, Let say I have a string with content "Free 100%". How can extract only "100" using ksh? I would this machanism to work if instead of "100" there is any kind of combination of numbers(ex. "32", "1238", "1"). I want to get only the digits. I have written something like this: ... (4 Replies)
Discussion started by: whatever
4 Replies

9. Shell Programming and Scripting

Help with regular expressions

I have following content in the file CancelPolicyMultiLingual3=U|PC3|EN RestaurantInfoCode1=U|restID1|1 ..... I am trying to use following matching extression \|(+) to get this PC3|EN restID1|1 Obviously it does not work. Any ideas? (13 Replies)
Discussion started by: arushunter
13 Replies

10. Shell Programming and Scripting

regular expressions

Hi, can anyone advise me how to shorten this: if || ; then I tried but it dosent seem to work, whats the correct way. Cheers (4 Replies)
Discussion started by: jack1981
4 Replies
Login or Register to Ask a Question