how can I add line number in textwrangler search and replace?

48 Views Asked by At

So I have a big text file with a string in the middle that looks like "id:" and I would like to add the line number as id value. So ideally I would be search and replacing something like:

Search for:

"id:

replace with:

"id:<line number>

Is that possible with Textwrangler?

1

There are 1 best solutions below

0
aMike On

Just for the record, for Linux and macOS, I put the following script in Textwrangler's "Text Filters" directory:

#!/bin/sh
/usr/bin/awk '/^"id:$/ {print $0 NR; next} {print}'

You can then run the filter from the 'Text/ Apply Text Filter...' menu.