Linux - SoftwareThis 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.
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 was wondering if there is a way to change the value of positional parameters inside a file.I mean, i want to change the value of a certain field of a file to the one i provide with?
how to do it with awk? i am trying to serach a file on a certain field.when i find it i have to number those records using "for" loop,inside the awk command.
This is my file
A100:Annie Marie's Dance Academy:123:1500
F110:Frankies Repair Shop:1123:250
S100:Sandra's Counselling Service:67:500
A100:Annie Marie's Dance Academy:254:500
I need the output in a report form like this:
Vendor Name: Annie Marie's Dance Academy
Here are the instructions:
It is recommended to use temporary files when matching valid vendor names to display the invoice and purchase amount information. You can then use command substitution and the set command to store vendor purchase information as positional parameters, and then use the for loop to display (hence number) each line...
I don't fully understand whether you want to CHANGE the values in the file, or SHOW the values from the file. Also, you already learned in another thread about this same exact subject, how to number the output lines using the NR variable from within `awk`. That thread is here: http://www.linuxquestions.org/questi...d.php?t=797911
Here's a way to SHOW the values; if you need to actually change them within the file, you'll want to use `sed` most likely.
Assuming the file you showed above is named "filename":
So, that just shows the entries for this vendor, which are inside the <filename>. To change the file, or put the results in a new file, I will leave that to you.
Also, I'll see about moving this thread to /programming, and/or joining it with its long lost friend, linked above
My previuos posts were little confusing.Actually i wanna search the file based on the first field in this case "A100" which has 2 entries in this file.Then i want to output a report which gives the name name of the vendor once and the numbered list for the transactions associated with it.Presently i am searching for the specific entries, putting it in a temporary file and then displaying the report for that specific entries. e.g
my temp file is :
1. A100:Annie Marie's Dance Academy:123:1500
2. A100:Annie Marie's Dance Academy:254:500
then i am using the command:
awk -F ":" 'BEGIN{printf "Purchases Detail\n===============\n\n"}{printf "Vendors Name :%s\n",$2}{printf "Invoice# %i\t",$3}{printf "Amount:$%5.2f\n",$4}{print $1}' temp2
which is giving me this output:
Enter the vendor number: A100
Purchases Detail
=================
Vendors Name :Annie Marie's Dance Academy
Invoice# 123 Amount:$123.00
Vendors Name :Annie Marie's Dance Academy
Invoice# 254 Amount:$254.00
but i need this output:
Vendor Name: Annie Marie's Dance Academy
1. Invoice #123 Amount: 1500
2. Invoice #254 Amount: 500
Now the problem is how to store the value of second field in a variable by separating it from the entire 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.