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.
I'm gonna prompt the user to enter a name and an amount. If the Name doesn't exist then I will add it. If the name exists, then I will have to add the amount that was already there with the amount that the user entered. I am having trouble with adding the amounts togeder. I don't know how to separate the amount from the name.
This is my work so far:
(I just started using sed and I have a feeling everything is wrong in my script so far.)
________________________________________
if sed "/$name*/" file
then
#need something here to calculate $amount3 that I used below
sed "s/$name*/$name,:,$amount3/g" file
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
well first of all you dont use sed to search a file, that would be the job of grep
and second.. sed by default dumps to stdout, i havnt't used sed enough to know the exact command to get it to actually EDIT the file but man sed would be a starting point if you havnt already
otherwise >> file2, move file1 to an archive rename file2 to file1
well first of all you dont use sed to search a file, that would be the job of grep
and second.. sed by default dumps to stdout, i havnt't used sed enough to know the exact command to get it to actually EDIT the file but man sed would be a starting point if you havnt already
otherwise >> file2, move file1 to an archive rename file2 to file1
I wouldn't use sed for your scenario
sed -i filename get's it to do an "inline" edit, however that doesn't deal with your calculation requirement.
How big is the datafile that you need to work on?
For small files (1000 lines or less) Ghostdog74's suggestion would be the easiest way to go.
Are you planning to test for unique names in the file?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.