Another sed/awk search=>replace question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Another sed/awk search=>replace question
# 1  
Old 08-28-2014
Another sed/awk search=>replace question

Hello,

Need a little bit of help. Basically I need to replace lines in a file which were calculated wrong as it would 12 hours to regenerate the data. I need to calculate values based on other files which I've managed to figure out with grep/cut but now am stuck on how to shove these new calculated values into another file

Code:
#!/usr/local/bin/bash
array=(61329025
61333750
61348174
61368157
61371144
61374807
61406775
61413072
61416814
61418304
61421223
61423127
61432337)

file2mod=sub_c18.csv

for i in "${array[@]}"
do
  a=`grep $i sub_c11* |cut -f2 -d","`
  b=`grep $i sub_c13* |cut -f2 -d","`
  c=`grep $i sub_c7* |cut -f2 -d","`
  ratio=`echo "$a+$b+$c-$a*$b-$a*$c-$b*$c" | bc -l`
  printf "%s, %0.8f\n" $i $ratio>>sanitycheck.txt
  sed -i "s/^a$i*//$i , $ratio/" $file2mod
done
echo "done"

sub_c18.csv looks like this
Code:
.
.
61406774,0.553508428
61406775,a2f14cf2
61406776,0.169964852
.
.

but it returns
Code:
sed: 1: "sub_c18.csv": unterminated substitute pattern

Thanks for any help.

Last edited by f77coder; 08-28-2014 at 01:12 PM..
# 2  
Old 08-28-2014
Welcome f77coder,

Thanks for using CODE tags straight away. It's a pleasure to have you here.

At first glance, your code defines a variable array but with and open parenthesis ( and a close brace } (I think they are the right names) so there is a mis-match. Is this a typo/copy & paste error, or could this be your problem?




Regards,
Robin

Last edited by rbatte1; 08-28-2014 at 12:49 PM.. Reason: Spleling
# 3  
Old 08-28-2014
Thanks but that's not the issue, in my code it has parenthesis. I'll fix it.
# 4  
Old 08-28-2014
In your sed statement there are 2 slashes next to each other. Perhaps that should be one?
# 5  
Old 08-28-2014
Thanks for reply.

I removed but still get this error.
Code:
ed: 1: "sub_c18.csv": unterminated substitute pattern

From what i've read the double '//' are needed to end the wildcard???
# 6  
Old 08-28-2014
Can you re-post your modified code...
# 7  
Old 08-28-2014
Sure. Thanks for looking.

Code:
#!/usr/local/bin/bash
array=(61329025
61333750
61348174
61368157
61371144
61374807
61406775
61413072
61416814
61418304
61421223
61423127
61432337)

file2mod=sub_c18.csv

for i in "${array[@]}"
do
  a=`grep $i sub_c11* |cut -f2 -d","`
  b=`grep $i sub_c13* |cut -f2 -d","`
  c=`grep $i sub_c7* |cut -f2 -d","`
  ratio=`echo "$a+$b+$c-$a*$b-$a*$c-$b*$c" | bc -l`
  printf "%s, %0.8f\n" $i $ratio>>sanitycheck.txt
  sed -i "s/^a$i*//$i , $ratio/" $file2mod
done
echo "done"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

2. Shell Programming and Scripting

Search and replace is not working by sed or awk

Hi , I have one file and in this file i have one like TEST1 KEY0=AAC040R1;AAC041R1ISE;AAC041R2ISE;AAC370R1;ADR0500;ADR0600;AME245R1;AME245R2;BAP0135;BAP0300;PPINVDTD*;PPJERPTD*;PPJERPT*;PRBSUMM*;: i want to replace this line with the following line TEST1... (4 Replies)
Discussion started by: ashissau
4 Replies

3. Shell Programming and Scripting

awk/sed to search & replace data in first column

Hi All, I need help in manipulating the data in first column in a file. The sample data looks like below, Mon Jul 18 00:32:52 EDT 2011,NULL,UAT Jul 19 2011,NULL,UAT 1] All field in the file are separated by "," 2] File is having weekly data extracted from database 3] For eg.... (8 Replies)
Discussion started by: gr8_usk
8 Replies

4. Shell Programming and Scripting

How to use SED or AWK to search and replace an exact string

I have a file DS1 DDS DS I want to replace only "DS" to "DSmail.blah.com" in a lot of files. I tried sed 's/DS/DSmail.blah.com' but it changes all the lines . thanks in advance (2 Replies)
Discussion started by: gubbu
2 Replies

5. Shell Programming and Scripting

awk/sed string search and replace

Need help with either sed or awk to acheive the following file1 ----- In the amazon forest The bats eat all the time... mon tue wed they would eat berries In the tropical forest The bats eat all the time... on wed bats eat nuts In the rain forest The bats eat all the time... on... (2 Replies)
Discussion started by: jville
2 Replies

6. Shell Programming and Scripting

Bash sed search and replace question

I have several files that I need to modify using sed. I know how to do that, but now a new requirement has come up. Now, I need to make changes to all lines that don't start with certain strings. For example, I need to change all lines except for lines that start with "a", "hello there",... (3 Replies)
Discussion started by: RickS
3 Replies

7. Shell Programming and Scripting

SED Question: Search and Replace start of line to matching pattern

Hi guys, got a problem here with sed on the command line. If i have a string as below: online xx:wer:xcv: sdf:/asdf/http:https-asdfd How can i match the pattern "http:" and replace the start of the string to the pattern with null? I tried the following but it doesn't work: ... (3 Replies)
Discussion started by: DrivesMeCrazy
3 Replies

8. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

9. Shell Programming and Scripting

search and replace with restriction (awk, sed)

Hello, i have a file like that foo A new bar A new bar B new I need to replace 'new' with 'done', but only in lines containing 'bar' AND 'A'. output file should then become foo A new bar A done bar B new Sorry im not able to figure it out, not even shure if i should take sed.... (10 Replies)
Discussion started by: knoxo
10 Replies

10. Shell Programming and Scripting

SED Search and Replace Question for Google Analytics

Well, I'm losing my regex ability in sed! Please help. I need to search for this text in multiple html files in a directory: </body> and add the following lines in front of the text above: <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> ... (11 Replies)
Discussion started by: Neo
11 Replies
Login or Register to Ask a Question