Swap value in column 1 Swap value in column 1 unix unix

Swap value in column 1


In GNU sed you could do like this:

sed -e 's/^23\>/X/' file.txt

Or using perl:

perl -pe 's/^23\b/X/' file.txt

Or using awk:

awk '{ if ($1 == 23) sub("23", "X"); print }' file.txt

If you want to update the file after the replacement, then you can use any of these commands:

sed -i -e 's/^23\>/X/' file.txtperl -pi -e 's/^23\b/X/' file.txt


Do you have access to any scripting languages? a perl or python script to replace a line start followed by 23 with a line start followed by X would be pretty simple.

see this answer: Find and Replace Inside a Text File from a Bash Command

so something like...

perl -pi -e 's/^23\s/X /g' /tmp/file.txt