Append a record to the end of a text file: Difference between revisions

no edit summary
No edit summary
Line 3,431:
out (in string f) endl console
end while</lang>
 
=={{header|Yabasic}}==
<lang Yabasic>a = open("passwd", "a") // Open the file for appending, i.e. what you write to the file will be appended after its initial contents.
// If the file does not exist, it will be created.
print #a "account:password:UID:GID:fullname,office,extension,homephone,email:directory:shell"
print #a "jsmith:x:1001:1000:Joe Smith,Room 1007,(234)555-8917,(234)555-0077,jsmith@rosettacode.org:/home/jsmith:/bin/bash"
print #a "jdoe:x:1002:1000:Jane Doe,Room 1004,(234)555-8914,(234)555-0044,jdoe@rosettacode.org:/home/jdoe:/bin/bash"
 
close #a
 
a = open("passwd", "a")
 
if not a error "Could not open 'passwd' for appending"
 
print #a "xyz:x:1003:1000:X Yz,Room 1003,(234)555-8913,(234)555-0033,xyz@rosettacode.org:/home/xyz:/bin/bash"
 
close #a
 
if (not open(a,"passwd")) error "Could not open 'passwd' for reading"
 
dim nameField$(1), contentField$(1)
 
line input #a a$
 
n = token(a$, nameField$(), ":,")
for i = 1 to n
if nameField$(i) = "account" field1 = i
if nameField$(i) = "homephone" field2 = i
next
 
print upper$(nameField$(field1)), "\t", upper$(nameField$(field2))
print
 
while(not eof(#a))
line input #a a$
n = token(a$, contentField$(), ":,")
print contentField$(field1), "\t", contentField$(field2)
wend
 
close #a</lang>
 
=={{header|zkl}}==
672

edits