Results 1 to 2 of 2
I need to replace a line in a file, example test.file:
Code:
cat test.file
DBAN 196157 5419883235 364173045 932 43933467 4915 256 21538970 4291 288 12197694 2809 1044 14041695 2782 ...
- 02-20-2009 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 10
replace a line in a file
I need to replace a line in a file, example test.file:
I'd have to replace always the second number from a specific line in a file, like:Code:cat test.file DBAN 196157 5419883235 364173045 932 43933467 4915 256 21538970 4291 288 12197694 2809 1044 14041695 2782 95 4526567 488 0 0 0 75 7120403 1678 43 CDALA 196157 5419883235 364173045 932 43933467 4915 256 21538970 4291 288 12197694 2809 1044 14041695 2782 95 4526567 488 0 0 0 75 7120403 1678 43 CSI 196157 5419883235 364173045 932 43933467 4915 256 21538970 4291 288 12197694 2809 1044 14041695 2782 95 4526567 488 0 0 0 75 7120403 1678 43
and then replace it with for example 2425212475 so the file would be:Code:grep CDALA test.file | awk '{print $3}
Code:cat test.file DBAN 196157 5419883235 364173045 932 43933467 4915 256 21538970 4291 288 12197694 2809 1044 14041695 2782 95 4526567 488 0 0 0 75 7120403 1678 43 CDALA 196157 2425212475 364173045 932 43933467 4915 256 21538970 4291 288 12197694 2809 1044 14041695 2782 95 4526567 488 0 0 0 75 7120403 1678 43 CSI 196157 5419883235 364173045 932 43933467 4915 256 21538970 4291 288 12197694 2809 1044 14041695 2782 95 4526567 488 0 0 0 75 7120403 1678 43
- 02-23-2009 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
try this:
grep CDALA <filename> | awk '{sub ($3, "2425212475");print}'
man awk
the sun is new every day (heraclitus)


Reply With Quote