The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace multiple lines between tags using sed dollylamb Shell Programming and Scripting 23 06-18-2009 03:44 PM
SED - Search and replace lines containing... pcwiz Shell Programming and Scripting 9 08-20-2008 06:36 PM
replace multiple lines in file nox Shell Programming and Scripting 2 08-18-2008 08:44 AM
Replace a perticular character of all lines of a file abovais Shell Programming and Scripting 1 12-11-2007 05:35 AM
how to replace one line in text with several lines FunnyCats UNIX for Dummies Questions & Answers 1 01-18-2007 09:52 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 03-16-2009
TehOne TehOne is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 55
Question replace lines in a file

I've got a file full of numbers, example:

Code:
cat test.file

60835287
0
51758036
40242437
0
32737144
0
24179513
0
4131489957
I want to replace those numbers

Code:
TMP2="/root/test.file"
for number in `cat $TMP2` ;do
     calc=$(awk -v a="$number" 'BEGIN{printf "%.2f\n GB",  a/1024/1024}')
     sed -i 's/$number/$calc/g' $TMP2
done
or

Code:
TMP2="/root/test.file"
for number in `cat $TMP2` ;do
     calc=$(awk -v a="$number" 'BEGIN{printf "%.2f\n GB",  a/1024/1024}')
     sed -e 's/$number/$calc/g' > test.txt
done
But it doesn't work at all, what is the problem? I'd guess it's something to do with the variables and sed, like it doesn't read them..

I've also tryd putting the sed command or variables into double quotes (sed -e "s/$number/$calc/g" > test.txt ) but that doesn't help either!
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0