Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
09-03-2015, 04:15 PM
|
#1
|
Member
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554
Rep:
|
Find and replace in one file with contents in a separate file
I am working with Volusion and want to change categories for products using libreoffice or by using bash as my info is in csv files. The problem is that my products download file shows categories only by id number (ie. 1, 2, 3, 4)
But I can download a separate categories file that has the id's in one column and the category name in another column.
I want to change the category id's in one file with the actual category name by using the data from the second file.
Here's an example:
---Product File---
Widget1 $19.95 1,3,5 ---Item is in 3 categories
Widget2 $24.95 2,4 ---this means it's in 2 categories
---Category File---
1 Books
2 Watches
3 Desks
4 Chairs
5 Doors
Hopefully this is possible to have my products file show up like this:
Widget1 $19.95 1,3,5 Books,Desks,Doors
Widget2 $24.95 2,4 Watches,Chairs
Is this even possible using libreoffice? If not, could I do this find and replace idea with a simple bash script?
I have 11,000 items and 1200 categories. This will save me a lot of time.
|
|
|
09-03-2015, 08:07 PM
|
#2
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,439
|
This seems to be a common sort of request - nothing in the "Similar threads" below ?.
Logic should be pretty straightforward - read the category file into an array, then use the numbers in the products records to index into the arrays and append the value. Personally I'd use awk.
|
|
|
09-03-2015, 08:42 PM
|
#3
|
Member
Registered: Jun 2006
Posts: 66
Rep:
|
Please, try this and see if it does what you want.
Code:
awk '
FNR==NR {
cat[$1]=$2
next
}
{
n=split($3, t, ",")
s=cat[t[1]]
for(i=2; i<=n; i++)
s=s "," cat[t[i]]
print $0, s
}' category.file product.file
Code:
Widget1 $19.95 1,3,5 Books,Desks,Doors
Widget2 $24.95 2,4 Watches,Chairs
Last edited by Aia; 09-03-2015 at 08:46 PM.
|
|
|
09-04-2015, 04:39 PM
|
#4
|
Member
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554
Original Poster
Rep:
|
Hey, that got me to it. Thanks
|
|
|
All times are GMT -5. The time now is 09:47 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|