Wednesday, May 6, 2015

Add the filename to each start of line on a file with SED

So you have a text file where you want to add the filename on each start of line for some reason so it can be easily managed as a csv or on Excel.

So do a dir /b > on the directory or create a list of files that require the filename as the begining of each line on those files:

In my example I have a bunch of file names inside asd.txt

for /f "tokens=*" %%i in (asd.txt) do sed "s/^/%%i;/" %%i


for /f "tokens=*" %%i in (asd.txt) do sed -i "s/^/%%i;/" %%i

That will add the filename and a semicolon

Such as:

And so on.


Post a Comment