Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add text in all of the rows

I am working in a linux environment and I would like to get some help on bash scripting to cut down on simple repetition.

I have long list of file names(937 to be exact). In that file on one row there is only one file name there, therefore, total of 937 lines in the file.

I would like to add certain text before the file name and add numbers after the file name in order.

so I would like something like this in the text file.

aa.exe

bb.exe

cc.exe

to

asd aa.exe 1

asd bb.exe 2

asd cc.exe 3

any help will be greatly appreciated.

like image 615
do yong kim Avatar asked Feb 20 '23 04:02

do yong kim


1 Answers

Just for kicks, here's an awk version:

awk '{print "foo", $0, NR}' files.lst 

If files.lst consists of:

a.txt
b.txt
c.txt

...then this will output:

foo a.txt 1
foo b.txt 2
foo c.txt 3
like image 116
Nate Kohl Avatar answered Feb 27 '23 10:02

Nate Kohl