A
A
abus-e2017-05-30 10:13:54
bash
abus-e, 2017-05-30 10:13:54

Linux Number a file?

There is a file, always with different number of lines.
You need to number it in order, so that it would be like this
text string num=1
text string num=2
text string num=3
etc ..
Or somehow else through the variable
text string num=$num
text string num=$num
text string num= $num
Our bash script generates files with different number of lines, we also need to number it

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xibir, 2017-05-30
@xibir

awk '{print $0,"num="NR;}' file.txt > result.txt

A
Anton Shvets, 2017-05-30
@Xuxicheta

I=$(($I+1)); echo $I
those. full command if not using sed or awwk

I=0; while read LINE; do I=$(($I+1)); echo "$LINE num=$I" >> newfile; done < file

A
abus-e, 2017-05-30
@abus-e

And how can I add? I need to enter this number in a certain place and then in order to the end of the lines

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question