Linux - Newbie This 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.
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.
|
 |
10-05-2006, 04:42 PM
|
#1
|
LQ Newbie
Registered: Oct 2006
Posts: 2
Rep:
|
shell script for changing a txt file content
Hi,
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
and run the v.sh , but didnt work.
Last edited by Flobsi; 10-05-2006 at 06:55 PM.
|
|
|
10-06-2006, 12:43 AM
|
#2
|
Member
Registered: Oct 2005
Location: A safe distance from Detroit
Distribution: SuSE 10.0, Knoppix
Posts: 99
Rep:
|
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.
|
|
|
10-06-2006, 02:08 AM
|
#3
|
Senior Member
Registered: Nov 2004
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
|
|
|
10-06-2006, 03:10 AM
|
#4
|
Member
Registered: Aug 2006
Location: Italy
Distribution: Fedora
Posts: 41
Rep:
|
You can use a for cicle:
Code:
for file in *.2.txt
do
gawk ' {print $1*2.1455E-07}' $file
done
If you want you can put this also in a bash script with the #!/bin/bash header, and making it executable..
|
|
|
All times are GMT -5. The time now is 12:57 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
|
|