have a fileA containing about 260 lines wherein i have to match 2 lines
fileA
I have to substitute the Amount2 value with the hashAmount value ie (-)15091500.0 with 15091500.0 (without the negative symbol)
hashAmount and Amount2 occur only once in the file
I have tried the following
echo $STR shows the value
I have to substitute this in place of the Amount2 line
i am getting the following error
further substitution to be done only
1) when hashAmount > 0
2) and when the difference between hashAmount and Amount2 is not more than 2 (i.e only when there is difference in decimal value
3) There are some 50 files on which i have to repeat this action
Regards
Last edited by Scott; 02-27-2010 at 03:40 PM..
Reason: Please use code tags
echo $STR shows the value
I have to substitute this in place of the Amount2 line
i am getting the following error
That's because you haven't told sed what to do when the patter "$STR" matches (missing command).
"/$STR/" matches the pattern, but you have to decide what to do after the match - print it ? delete it ? substitute it ?
"char 19" tells you that the command should've been at the 19th char position; check the characters in the expansion => /Amount2 15091500/
You probably wanted to do something like this -
Quote:
further substitution to be done only
1) when hashAmount > 0
2) and when the difference between hashAmount and Amount2 is not more than 2 (i.e only when there is difference in decimal value
3) There are some 50 files on which i have to repeat this action
Here's a Perl solution to perform this processing.
I've assumed that the files of interest are the ones that end with ".txt" extension. It needn't be ".txt"; it can be any appropriate regular expression in the glob function.
So,
- Amount2 in f1.txt should be substituted.
- Amount2 in f2.txt should not be substituted because hashAmount < 0 (violation of Rule 1).
- Amount2 in f3.txt should not be substituted because hashAmount - Amount2 = 35 - (-34) = 69 which is > 2 (violation of Rule 2).
Here's the Perl program to do that. The inline script comments should be self-explanatory.
I am trying to use nawk sub to substitute a string in a file. Both the pattern and the replacement I set as variables using bash.
here is the code:
#!/bin/bash -x
ydate=`/usr/local/bin/date +%Y%m%d`
echo $ydate
test_ca=/home/mdadmin/test_ca
for i in `cat ${test_ca}`
do
if ]; then... (9 Replies)
I am using script for substitute one variable with another variable like below...
below code works fine...
sed 's/'$sub_fun'/'$To_sub'/g'
But when i run the same code from the script getting below errors..
sed: -e expression #1, char 7: unterminated `s' command
please help....... (2 Replies)
Hey guys,
I know that title is a mouthful - I'll try to better explain my struggles a little better...
What I'm trying to do is:
1. Query a db and output to a file, a list of column data.
2. Then, for each line in this file, repeat these values but wrap them with:
ITEM{
... (3 Replies)
Hi guys,
I'm trying to figure out how to use a shell variable inside my sed command.
I just want to remove a certain part of a path. I've tried three different combinations and none of them work. Here are the three combinations:
echo $file | sed 's/'$test'//'
echo $file | sed "s/$test//"... (7 Replies)
Hi Gurus
this is working finee with tested values
#!/bin/ksh
V_DATE="2007-11-30"
V_ID=789
V_NAME="john_${V_ID}_has_${V_DATE}_s"
FILE_NAME=`echo ${V_NAME}`
echo ${FILE_NAME}
Buttt the problem is
the first two values will come dynamically
and the file will looks like... (2 Replies)
Can SED be used to substitute a character (y) with a character (Y) in a specified field?
File has 12000 : delimeted rows as;
HHC 1 BDE:Lastname, Firstname MI:firstname.mi.lastname@mil:SGT
HHC 2 BDE:Lastname, Firstname MI:Firstname.MI.Lastname@mil:SGT
I wish to replace the capital letters... (6 Replies)
I have a Linux C program I'm writing that has one section where, within a large string, I need to substitute a smaller string for another, and those probably won't be the same size.
For instance, if I have a string:
"Nowisthetimeforallgoodmen"
and I want to substitute 'most' for 'all' the... (2 Replies)
Hello
please how can i change this infrormation within a file dynamically without using vi " || $6 ~ /^229*/ " the * means any number within
the file has this content :
cat lec|awk -F '|' 'length($6) >= 12 || length($6) <= 10' |awk -F '|' '$6 ~ /^24/ || $6 ~ /^22924/ &&$7 ~... (1 Reply)
Hi,
I have a program in which i have to substitute a TAG in a file with the value of a variable.
Code Snippet:
----------------
myvar=1234
sed 's/_TAG_/$myvar/' infile outfile
When I run this command, the _TAG_ in the "infile" is substituted with "$myvar" but NOT the value "1234"... (1 Reply)