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 am new to Linux and try to figure out the best way to change the content of a txt file writing a shell script.
the txt file consists of one row with different numbers,like:
1.057353E-04
2.068785E-01
....
I want each of that numbers multiplied by 2.1455e-07.
So far I tried to pipe the txt-files into gawk with:
ls *.2.txt | gawk ' {print$1*2.1455E-07} ' >v.sh
then added the header in the output v.sh file with:
#!/bin/sh
Well, first off, 'ls *.2.txt' won't spit out the contents of the file(s), it will only list the file name(s), then pass that to gawk. You need to 'cat' the file to read out the contents. I also can't guarantee that your syntax for gawk will do what you expect it to without trying it. Then on top of that, even if it gave you the output you were expecting, just redirecting it to a file and adding that header won't make it run. You'll probably need to use chmod to add the execute bit before it will do anything, and I suspect it isn't going to do what you want.
You really want the script to read one value at a time from the file, then manipulate it and output the results, either to the screen or to a file.
What you really want to do is find a book or tutorial on shell scripting to learn how to do this, or even better, look into Perl to do this.
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,606
Rep:
I am pretty sure you can do the multpication within awk http://www.gnulamp.com/awk.html
{ print ($1^2)+1 }
You may have a syntax error, you may need some brackets
NB: Numerical accuracy if you start * small No together with awk,
I have no idea what libraries are behind it
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.