ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am not quite sure how to attack this one. I have a CSV file (see example below). I need to clean up the first column. In the area that has quotes I just want Jsmith, I want the cn= and everything past the Jsmith gone in the quotes. See below.
How my CSV looks:
"cn=Jsmith,ou=Employee,ou=Library,o=Users”,Jsmith2,,,jim@email.com,jim
What I need after clean up
Jsmith,Jsmith2,,,jim@email.com,jim
[root@dev ~]# echo "cn=Jsmith,ou=Employee,ou=Library,o=Users”,Jsmith2,,,jim@email.com,jim" | sed -r 's/^[^=]+=([^,]+).*"/\1/'
cn=Jsmith,ou=Employee,ou=Library,o=Users”,Jsmith2,,,jim@email.com,jim
[root@dev ~]# sed --version
GNU sed version 4.2.1
[root@dev ~]# echo "cn=Jsmith,ou=Employee,ou=Library,o=Users”,Jsmith2,,,jim@email.com,jim" | sed -r 's/^[^=]+=([^,]+).*"/\1/'
cn=Jsmith,ou=Employee,ou=Library,o=Users”,Jsmith2,,,jim@email.com,jim
[root@dev ~]# sed --version
GNU sed version 4.2.1
I had to update my sed command to 4.2.2 and it worked fine. I am working in OS X so I had to update via MacPorts. Maybe you can update yours via yum?
@szboardstretcher - The issue is you copied the input from the user and the second set of double quotes is actually something else ... not sure what. Also, if you use double quotes around double quotes
you will lose the original form, try:
Code:
echo '"cn=Jsmith,ou=Employee,ou=Library,o=Users",Jsmith2,,,jim@email.com,jim' | sed -r 's/^[^=]+=([^,]+).*"/\1/'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.