Answers for "append line in file"

12

append a line to a text file python

# Open a file with access mode 'a'
file_object = open('sample.txt', 'a')
 
# Append 'hello' at the end of file
file_object.write('hello')
 
# Close the file
file_object.close()
Posted by: Guest on March-18-2020
0

how to add line inside a file

how to add lines inside a file

sed -i -e "48r../../../../folder1/lines_to_add.txt" a.txt 

a.txt - file you want to change
48r is line number of a.txt 
some lines are inside lines_to_add.txt file
../../../../scripts3_2d/lines_to_add.txt 
-i update a.txt, try without -i before runthe code,
be carefull with newlines, 
"keep a newline at the end of lines_to_add.txt"
Posted by: Guest on June-09-2021

Code answers related to "append line in file"

Python Answers by Framework

Browse Popular Code Answers by Language