parsing out from rpm -qa --queryformat into CSV output
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
parsing out from rpm -qa --queryformat into CSV output
I found several different web sites talking about this but my problem is slightly different and I haven't been able to find an answer anywhere. When querying the RPM database usin TAGS like
rpm -qa --qf '%{NAME} %{VERSION}.%{RELEASE} %{SUMMARY} %{VENDOR} %{DESCRIPTION} %{INSTALLTIME:date}\n'
I get tabbed output I am looking for except the output from the DESCRIPTION tag contains LF characters so when importing it into an excel spreadsheet, every line from the DESCRIPTION tags causes a new line. I'm looking for the the ability to run the above RPM command and have the output from each of the TAGS separated by tabs with no cr or lf so they will correctly import into a spreadsheet where each TAG has it's own column. I've tried using tr to change \n to a space (|tr '\n' ' ') but then all of the output is one continuous line. I think I'm close but just can't quite see it.
Thoughts?
I found several different web sites talking about this but my problem is slightly different and I haven't been able to find an answer anywhere. When querying the RPM database usin TAGS like
rpm -qa --qf '%{NAME} %{VERSION}.%{RELEASE} %{SUMMARY} %{VENDOR} %{DESCRIPTION} %{INSTALLTIME:date}\n'
I get tabbed output I am looking for except the output from the DESCRIPTION tag contains LF characters so when importing it into an excel spreadsheet, every line from the DESCRIPTION tags causes a new line. I'm looking for the the ability to run the above RPM command and have the output from each of the TAGS separated by tabs with no cr or lf so they will correctly import into a spreadsheet where each TAG has it's own column. I've tried using tr to change \n to a space (|tr '\n' ' ') but then all of the output is one continuous line. I think I'm close but just can't quite see it.
Thoughts?
So you want to remove line feeds but don't want the output to be on a single line? To me, this is a contradiction.
You might be more successful by putting double quotes around the %{DESCRIPTION}, hoping that there are no double quotes inside the %{DESCRIPTION}. Should be feasible with a pipeline of sed commands - first convert double quotes to something else, then add them around the description.
The output from each TAG (NAME,VERSION,SUMMARY etc) is currently separated by a tab and has no lf in the output. The DESCRIPTION output, because it can be longer,does have lf in the output so when attempting to input it into Excel or similar, the DESCRIPTION output ends up taking up multiple cells instead of just using one cell in the spreadsheet like all of the other TAGS. I'd like to be able to strip the lf from the DESCRIPTION output only. That way all of the TAGS would be on one line but separated by TABS so they would successfully import into Excel. I will play around with SED and see what I can come up with.
Quote:
Originally Posted by berndbausch
So you want to remove line feeds but don't want the output to be on a single line? To me, this is a contradiction.
You might be more successful by putting double quotes around the %{DESCRIPTION}, hoping that there are no double quotes inside the %{DESCRIPTION}. Should be feasible with a pipeline of sed commands - first convert double quotes to something else, then add them around the description.
Quote:
Originally Posted by berndbausch
So you want to remove line feeds but don't want the output to be on a single line? To me, this is a contradiction.
You might be more successful by putting double quotes around the %{DESCRIPTION}, hoping that there are no double quotes inside the %{DESCRIPTION}. Should be feasible with a pipeline of sed commands - first convert double quotes to something else, then add them around the description.
If you got rid of the DESCRIPTION and only used the SUMMARY (why both anyway), you might find the problem goes away.
I had a play using awk, but it could get ugly.
Removing the DESCRIPTION TAG definitely removes the problem as it's the only output with lf in it. I was just keeping the DESCRIPTION tag because it provides a lot more detail.
Quote:
Originally Posted by syg00
If you got rid of the DESCRIPTION and only used the SUMMARY (why both anyway), you might find the problem goes away.
I had a play using awk, but it could get ugly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.