Reputation: 1
I am struggling with some python code.
I have a file with many lines e.g
50
22
35
41
I wish to add these into a sentences of similar structure however keeping the order of the lines.
E.g
This is test 50 of this friday
This is test 22 of this friday
This is test 35 of this friday
This is test 41 of this friday
Upvotes: 0
Views: 53
Reputation: 195179
sed one-liner
sed 's/.*/This is test & of this friday/' file
or python (2.7)
with open('file') as f:
for x in f:
print "this is test %s of this friday" % x.strip()
Upvotes: 0
Reputation: 3087
Fairly easy in Python:
with open('file.txt') as f:
for line in f:
print("This is a test {} of this friday".format(line.strip()))
Upvotes: 1
Reputation: 85845
You tagged the question with python
and awk
. For something this trivial awk
seems the clear choice:
$ awk '{printf "This is a test %d of this friday\n",$0}' file
This is a test 50 of this friday
This is a test 22 of this friday
This is a test 35 of this friday
This is a test 41 of this friday
Upvotes: 1