Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-05-2006, 05:42 PM   #1
LQ Newbie
Registered: Oct 2006
Posts: 2

Rep: Reputation: 0
shell script for changing a txt file content


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:


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} ' >

then added the header in the output file with:

and run the , but didnt work.

Last edited by Flobsi; 10-05-2006 at 07:55 PM.
Old 10-06-2006, 01:43 AM   #2
Registered: Oct 2005
Location: A safe distance from Detroit
Distribution: SuSE 10.0, Knoppix
Posts: 98

Rep: Reputation: 17
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.
Old 10-06-2006, 03: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: Reputation: 53
I am pretty sure you can do the multpication within awk
{ 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
Old 10-06-2006, 04:10 AM   #4
Registered: Aug 2006
Location: Italy
Distribution: Fedora
Posts: 41

Rep: Reputation: 15
You can use a for cicle:

for file in *.2.txt
gawk ' {print $1*2.1455E-07}' $file
If you want you can put this also in a bash script with the #!/bin/bash header, and making it executable..


shell, shell script

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Does anyone know of a bash script can search & replace txt in a file. jimwelc Linux - Newbie 6 09-15-2008 01:13 AM
modify content in a file using shell script fjkum Linux - Newbie 2 08-03-2006 05:46 AM
Shell script: substitute a file's content according to a map? Chowroc Programming 11 11-15-2005 05:08 AM
use file content as tcl script parameters powah Linux - General 3 07-16-2005 12:10 PM
Perl Script Reading a txt file and generate html to be published! kofi Linux - Software 1 09-22-2003 06:12 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:26 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration