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

no edit summary
(Added Wren)
No edit summary
Line 1,849:
xyz.shell = "/bin/bash"
append(xyz, ".passwd")</lang>
=={{header|M2000 Interpreter}}==
<lang M2000 Interpreter>Module TestThis {
Class passwd {
account$, password$
UID, GID
group GECOS {
fullname$,office$,extension$,homephone$,email$
function line$() {
=format$("{0},{1} {2},{3},{4}", .fullname$,.office$,.extension$,.homephone$,.email$)
}
}
directory$, shell$
Function Line$() {
=format$("{0}:{1}:{2}:{3}:{4}:{5}:{6}",.account$,.password$, .UID, .GID, .GECOS.line$(), .directory$, .shell$)
}
class:
Module passwd {
if match("SSNNSSSSSSS") then
Read .account$, .password$
Read .UID, .GID
For .GECOS {
Read .fullname$,.office$,.extension$,.homephone$,.email$
}
Read .directory$, .shell$
Else.If Match("S") then
Dim a$(), b$()
a$()=Piece$(letter$, ":")
.account$<=a$(0)
.password$<=a$(1)
.UID<=Val(a$(2))
.GID<=Val(a$(3))
For .GECOS {
b$()=Piece$(a$(4), ",")
.fullname$<=b$(0)
.office$<=Piece$(b$(1), " ")(0)
.extension$<=Piece$(b$(1), " ")(1)
.homephone$<=b$(2)
.email$<=b$(3)
}
.directory$<=a$(5)
.shell$<=a$(6)
End if
}
}
Flush
Data PASSWD("jsmith", "x", 1001, 1000, "Joe Smith", "Room", "1007","(234)555-8917","(234)555-0077","jsmith@rosettacode.org","/home/jsmith","/bin/bash")
Data PASSWD("jdoe:x:1002:1000:Jane Doe,Room 1004,(234)555-8914,(234)555-0044:jdoe@rosettacode.org:/home/jdoe")
\\ we have to make the file if not exist before we use APPEND
if not exist("passwd") then
Open "passwd" for Output as #F
Close #F
end if
Open "passwd" for wide append as #F
While not empty
read A
Print #F, A.line$()
End While
Close #F
Ret=PASSWD("xyz","x",1003,1000,"X Yz", "Room", "1003", "(234)555-8913", "(234)555-0033", "xyz@rosettacode.org","/home/xyz","/bin/bash")
Repeat
Try ok {
Open "passwd" for wide append exclusive as F
Print #F, Ret.line$()
close #F
}
Until Not (Error or Not ok)
I=1
Document Ret$
Open "passwd" for wide input as #F
While not Eof(#F)
Line Input #F, record$
Ret$=Format$("{0}|{1}",Str$(I,"0000"),Record$)+{
}
I++
End While
Close #F
ClipBoard Ret$
Report Ret$
}
TestThis
</lang>
{{out}}
<pre>
0001|jsmith:x:1001:1000:Joe Smith,Room 1007,(234)555-8917,(234)555-0077:jsmith@rosettacode.org:/home/jsmith
0002|jdoe:x:1002:1000:Jane Doe,Room 1004,(234)555-8914,(234)555-0044:jdoe@rosettacode.org:/home/jdoe
0003|xyz:x:1003:1000:X Yz,Room 1003,(234)555-8913,(234)555-0033:xyz@rosettacode.org:/home/xyz
</pre>
 
 
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
404

edits