Skip to content
Advertisement

replace text between two tabs – sed

I have the following input files:

text1 text2 text3 text4
abc1 abc2 abc3 abc4

and I am trying to find the second string between the two tabs (e.g. text2, abc2) and replace it with another word.

I have tried with

sed s'/t*t/sample/1'

but it only deletes the tab and does not replace the word.

I appreciate any help!

Advertisement

Answer

I would suggest using awk here:

awk 'BEGIN { FS = OFS = "t" } { $2 = "sample" } 1' file

Set the input and output field separators to a tab and change the second field. The 1 at the end is always true, so awk does the default action, { print }.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement