user42298
user42298

Reputation: 1911

linux paste column to other file

I have many files named 0.250, 0.252, 0.254 .... and each file contains some numbers, like

0.2520 0.2520 0.2520
0.2520 0.2520 0.7440
0.2520 0.7440 0.2520
0.7440 0.2520 0.2520

and I want to paste a column

1
2
3
4

to each file, so my files 0.250, 0.252 .. to be modified as

1 0.2520 0.2520 0.2520
2 0.2520 0.2520 0.7440
3 0.2520 0.7440 0.2520
4 0.7440 0.2520 0.2520

I tried paste command, but this doesn't change the actual file..

Upvotes: 0

Views: 738

Answers (3)

choroba
choroba

Reputation: 241868

Use nl to number lines.

nl -s' ' -ba -nln -w1 < input > output

Upvotes: 1

William Pursell
William Pursell

Reputation: 212248

It looks like you want:

for file in *; do
  nl "$file" > "$file.numbered"
done

Upvotes: 1

chris
chris

Reputation: 41

You can redirect the output of the paste command to a file...

paste file1 file2 > outputfile

Consider creating new files, and then removing the old ones instead of replacing them on the spot. It is much much safer...

Upvotes: 1

Related Questions