sed/awk to find and replace (multiple files)

December 16, 2010 at 00:54:11
Specs: ubuntu, core 2 solo/2 gb
I want to find a particular string in file(first file) and replace that string with a value from another file(second file) using sed/awk or any other way. the second file has one line only. please help me!!! i am new to this :(((

See More: sed/awk to find and replace (multiple files)

Report •

#1
December 16, 2010 at 11:17:01
#!/bin/bash

# get your one line of text into a shell variable
myvar=$(cat newfile.txt)

# replace string: old string: with the variable above
# surround the varialbe with #!/bin/bash

# get your one line of text into a shell variable
myvar=$(cat newfile.txt)

# replace string: old string: with the variable above
# surround variable in sed script with '"
sed 's/old string/'"${myvar}"'/g' mydatafile.txt


Report •
Related Solutions


Ask Question