bash - serialized numbers in text files with for loop and sed -
i want put serialized numbers on defined positions in text file. idea use character patterns in file, count variable , put them using sed in file. tried this:
for number in 1 2 3 4 ; sed -ibak "s/var/$number" file.txt > file2.txt done (the arguments 1 2 3 ... not best solution, think, should work)
with code , tiny variations of it, different results, no success. can cut/paste pattern in text, last argument inserted (="3"). why doesn´t sed take iterated variable? (which counted up, tested echo).
the first iteration replaces var 1, next iteration replaces same var 2, etc. - because operate on same input every time, , pattern isn't dynamic.
it's not clear want achieve, it's hard provide working solution.
it might easier reach perl:
perl -pe 's/picvar/"pic" . ++$i/e'
Comments
Post a Comment