LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash scripting - editing files (https://www.linuxquestions.org/questions/programming-9/bash-scripting-editing-files-69124/)

brian0918 06-30-2003 05:47 PM

bash scripting - editing files
 
How would you, for example, replace the number in the Nth column (columns are consecutive characters separated by blank space) of the line that contains "bleh" in the file called FILENAME with 12345?

Thanks.

Hko 06-30-2003 06:16 PM

Code:

#!/bin/sh

FILENAME="$HOME/file.txt"

mv -f ${FILENAME} ${FILENAME}.old
awk '/bleh/{$4=12345 ; print}' ${FILENAME}.old >${FILENAME}



All times are GMT -5. The time now is 03:58 AM.