sed replace in-line a specific column number value at a specific line number

前端 未结 2 892
旧时难觅i
旧时难觅i 2021-02-04 20:23

I have a 5 columns csv file (space separated) like this :

username1 20130310 enabled 20130310 enabled
username2 20130310 enabled 20130321 disabled
username3 2013         


        
2条回答
  •  旧巷少年郎
    2021-02-04 20:56

    This might work for you (GNU sed & Bash):

    lineNumber=4 newValue=xxxx sed -i ${lineNumber}'s/\S\+/'"${newValue}"'/4' file
    

    However beware. If the newValue contains a / you will need to change the substitute command delimiter to something else e.g. s@\S\+@${newValue}@4

提交回复
热议问题