Hi Everyone,
I am new to this forum and new to sed/awk programming too !!
I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column.
file 1:
(assert (= c OUT))
file 2:
OUT 0
NOW, I HAVE TO REPLACE 'OUT' WITH THE VALUE 0.
please pleeaseee tell me how to do this using sed/awk or any other way!!! am in distress!! HELP
Guys thanx for replying!!
But will these solve my problem? since where exactly are we searching the string 'OUT' here? I actually have similar other strings to search and replace with other values from other files.. actually this is the case:
(define argc :: float)
(assert (> c 0))
(assert (= c OUT))
<check>
.
.
.
file2:
main 1
file 3:
main 0
.
.
.
Now, I have to find the string 'ARG' from file 1 and replace it with the value '1' from file 2. And, find 'OUT' and replace it with the value '0' from file 3.
If you have too many files like file2, file3,....file50
Then all above files can be concatenated into one say a temp file..
then use temp file and change values in file1.
Then go with ctsgnb in post #3
I had a file which had all this data... I had separated it only
actually the data in file 2, 3, 4 etc are divided into 2 files... i have to merge them. okay i will see this and get back to you. thanx a ton!! :))
---------- Post updated at 11:50 PM ---------- Previous update was at 11:48 PM ----------
does the link u gave show how to concatenate files into a single?
---------- Post updated 12-17-10 at 12:06 AM ---------- Previous update was 12-16-10 at 11:50 PM ----------
ques---->
does a and b signify the strings i want to find?
a is first string (i.e. OUT) and b is 2nd string (i.e. 0)
and in
sed -i "s/$a/$b/g" file1
$a will be replaced by $b
If you don't have file2, file3, ..., file50 concatenate into one already then you need few lines of script to do that 1st. If you are facing problem in this, pls tell all such files and there names (name format)
Hi.. thx so much for the quick reply!! I just want to separate the blocks and send it as an argument to a tool(yices). a shell script for that i want.. i am new to linux environ..
basically i am developing a diagnostic tool..(a debugging project)
i need to do some text editing and send the text to yices(whole file). if the result is 'unsat' i need to separate the blocks and send each to diagnose where the problem lies.. Now you got it? does it make sense? i have other problems too.. will post another thread for that
First column value in both Stack.txt and Output.txt are same. I hope this is not the case. If same, then value in 1st file (Stack.txt) will be in final output.
cat Stack.txt Output.txt > Data.txt
while read a b
do
sed -i "s/$a/$b/g" file1
done <Data.txt
If -i switch in sed doesn't wrok, then you need to you a temp file as below:
hi anurag,
u r right... it will be like this:
data.txt:
main: ARG 1
function1: F1 1
function2: F1' 1
main: OUT 0
function1: F2 1
function2: F2' 0
now it becomes little difficult actually:
i have to replace ARG in the first file(see main post) with the corresponding value for ARG ie '1' . similarly for F1, value 1 etc. now ill the previous code work? i have to match the string and get the corresponding value .. how will i do that?
I do not want to replace with fixed values. I have to search for the string OUT in the new file(data.txt) and replace the OUT in file1 with the corresponding value(it may be 0/1/2/3 , anything)
that is have to grep for OUT in the file and find the value that is beside it!!
Right. That's what above script is doing.
It's reading Data.txt and putting 1st column value in a , 2nd column value in b and 3rd column value in c.
Then all occurences of b in file1 is being replaced by c.
I hope this is what you want.