• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Batch edit of line in text files

BarkingGhostar

Diamond Member
I need to edit a large number of text files. Specifically, I need to edit one line in a text file from XXX to XXX_AABBCC where AABBCC is the date. Also, these text files do not end in 'txt' but something else, but are text files that are easily associated with Notepad or some other simple editor.

The number of files is usually 150-700. Just need the solution to open each file, look for XXX and replace with XXX_AABBCC.
 
unix tools (sed, awk, ...) are useful for doing such batch editing with raw/text files

(cygwin on windows will give you those tools as well. You can see how simple it is to do, and can be automated if it needs to be done often)

Code:
export DATE=`date +"%m%d%y"` && find . -type f -exec sed -i "s/XXX/XXX_$DATE/g" {} \;

export DATE=`date +"%m%d%y"`=> set the environment variable DATE with today's date (change it to a static string if you want to)

find . -type f=> get a list of all files in this directory/subdirectory. you can add a name qualifier (-name "*.txt")

-exec => execute the following command for those files listed

sed -i "s/XXX/XXX_$DATE/g" {} \; => sed is a program, "-i" means to edit the file in place

substitute XXX with XXX_<today's date>
 
Last edited:
Back
Top