💻 Software
Am I using sed properly to perform this conditional replace? Is there a better way?
Fresh5 days ago
Mar 15, 20262681 viewsConfidence Score0%
0%
Problem
I have a space-delimited file that's about 3200 lines long. Each line contains 7+ fields. What I would like to do is edit the file with so that every line containing a certain variable in field 5 would have its field 1 changed to X. What I'm thinking is to do something like: Is this correct? Is the…
Error Output
for variable in `cat word.list.file` do sed 's/line_with_$variable_in_field5/replace_field1_with_X/g' old.file > new.file cp new.file old.file …
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Canonical Fix
Unverified Fix
New Fix – Awaiting Verification
Fix for: Am I using sed properly to perform this conditional replace? Is there a better way?
Low Risk
This prevents having to read each file many times. It reads each file just once. Explanation: Use the files "word.list.file" and "old.file" as input. Write output to "new.file". If the whole operation doesn't produce an error ( ), then rename "new.f…
Awaiting Verification
Be the first to verify this fix
Sign in to verify this fix