To read specific line from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To read specific line from a file
# 1  
Old 03-10-2013
To read specific line from a file

Hi,

I have a ldif file like below:
Code:
version: 1

dn: cn=Test Group,ou=Applications,dc=xyz,dc=com
objectClass: groupOfUniqueNames
objectClass: top
cn: Test Group
uniqueMember: uid=abc,ou=People,o=xyz,o=Corporate,dc=xyz,dc=com

dn: cn=Test Sub Group,cn=Test Group,ou=Applications,dc=xyz,dc=com
objectClass: groupOfUniqueNames
objectClass: top
cn: Test Sub Group
uniqueMember: uid=def,ou=People,o=xyz,o=Corporate,dc=xyz,dc=com
uniqueMember: uid=fgh,ou=People,o=xyz,o=Corporate,dc=xyz,dc=com


I need to output from above file as :
Code:
uid=abc,ou=People,o=xyz,o=Corporate,dc=xyz,dc=com
uid=def,ou=People,o=xyz,o=Corporate,dc=xyz,dc=com
uid=fgh,ou=People,o=xyz,o=Corporate,dc=xyz,dc=com

Please help.
# 2  
Old 03-10-2013
grep "uid=" filename | awk '{print $2}'
# 3  
Old 03-10-2013
Code:
awk '$2~"uid" {print $2}' file

Or
Code:
sed -n "s/[^ ]* uid/uid/p" file

# 4  
Old 03-10-2013
Quote:
Originally Posted by PikK45
grep "uid=" filename | awk '{print $2}'
This is Useless Use of grep | awk

Another approach using GNU grep:
Code:
grep -o "uid.*" file

This User Gave Thanks to Yoda For This Post:
# 5  
Old 03-11-2013
Thanks a lot ,

All worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

2. Shell Programming and Scripting

Read command stop on either EOF or a specific line

I'm trying to stop reading a file until the end of the file is reached or a defined delimiter line is reached. Some how I need to test the fail state of the last 2 commands, not just the last command. echo -e "hello\ngoodbye\n####\ntesting" | while read line; ]; do echo "$line"; done hello... (4 Replies)
Discussion started by: Michael Stora
4 Replies

3. Shell Programming and Scripting

How to read particular line in file from specific column?

Hi...friends.... I want to create inventory...information for that I need to read some specific row say 2nd row from 1st 3 column and and write data with particular file used, I have some more column also but I need only 3 column data of first entry after header I attached sample file..those... (12 Replies)
Discussion started by: nex_asp
12 Replies

4. Shell Programming and Scripting

Read file from nth line to specific character

Hi, I want to read the file from nth line (where n is an integer) to until I encounter @ char. Can any one please help me how to do this? Thanks. (3 Replies)
Discussion started by: laalesh
3 Replies

5. Shell Programming and Scripting

how read specific line in a file and write it in a new text file?

I have list of files in a directory 'dir'. Each file is of type HTML. I need to read each file and get the string which starts with 'http' and write them in a new text file. How can i do this shell scripting? file1.html <head> <url>http://www.google.com</url> </head> file2.html <head>... (6 Replies)
Discussion started by: vel4ever
6 Replies

6. Shell Programming and Scripting

How to read from specific line number in shell script?

I have a text file which is having 30000 lines in it. I have to create a xml file for each 10000 lines until all the lines in the text files are written. Also please help how can i get number of lines in the text file in a shell variable? (19 Replies)
Discussion started by: vel4ever
19 Replies

7. Shell Programming and Scripting

Using awk to read a specific line and a specific field on that line.

Say the input was as follows: Brat 20 x 1000 32rf Pour 15 p 1621 05pr Dart 10 z 1111 22xx My program prompts for an input, what I want is to use the input to locate a specific field. Like if I type in, "Pou" then it would return "Pour" and just "Pour" I currently have this line but it is... (6 Replies)
Discussion started by: Bungkai
6 Replies

8. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

9. Shell Programming and Scripting

How to read the value from a specific line and column BASH

Hi All, I have the same problem as the one posted in https://www.unix.com/shell-programming-scripting/96097-how-read-value-specific-line-column-csh-variable.html but I'm using bash. Can anyone tell me how I have to modify the code to make it bash compatible? eval `awk 'NR==3{print "set... (5 Replies)
Discussion started by: f_o_555
5 Replies

10. Shell Programming and Scripting

A script that read specific fileds from the 7th line in a file

Dear All, I need a unix script that will read the 7th line and especially these fileds from a file Mo speed 16, Mt speed 15 every 15 minutes starting from 00:00 to 23:45 on daily basis and put the result in a txt file and name it MT_MO_20090225.txt, please also note that the system date format... (2 Replies)
Discussion started by: samura
2 Replies
Login or Register to Ask a Question