SlideShare a Scribd company logo
18IS33-UNIX and Shell Programming (Scheme and Solution) Page 10
Signature of the QuestionPaperSetter:
:
Signature of Scrutinizer
Subject Titles: UNIX and Shell Programming. Subject Code: 18IS33
Q.No. Solutions Marks
Allotted
10.c) File andling
To access a file on your UNIX file system from within your Perl program, you must perform the
following steps:
1. First, your program must open the file. This tells the system that your Perl program wants to
access the file.
2. Then, the program can either read from or write to the file, depending on how you have
opened the file.
3. Finally, the program can close the file. This tells the system that your program no longer
needs access to the file.
To open a file we use the open() function. open(INFILE, /home/srm/input.dat”);
INFILE is the file handle. The second argument is the pathname. If only the filename is
supplied, the file is assumed to be in the current working directory.
open(OUTFILE,”>report.dat”); # Opens the file in write mode open(OUTFILE,”>>report.dat”);
# Opens the file in append mode
The following script demonstrates file handling in perl. This script copies the first three lines of
one file into another.
#!/usr/bin/perl
open(INFILE, “desig.dat”) || die(“Cannot open file”);
open(OUTFILE, “>desig_out.dat”);
while(<INFILE>) {
print OUTFILE if(1..3);
} close(INFILE); close(OUTFILE);
6M

More Related Content

What's hot

Unix system programming
Unix system programmingUnix system programming
Unix system programming
Syed Mustafa
 
Systemcall1
Systemcall1Systemcall1
Systemcall1
pavimalpani
 
Linux day 2.ppt
Linux day  2.pptLinux day  2.ppt
Linux day 2.ppt
Kalkey
 
Introduction to linux
Introduction to linuxIntroduction to linux
Introduction to linux
Gourav Varma
 
4 text file
4 text file4 text file
4 text file
hasan Mohammad
 
Computer Forensics &amp; Windows Registry
Computer Forensics &amp; Windows RegistryComputer Forensics &amp; Windows Registry
Computer Forensics &amp; Windows Registry
somutripathi
 
Linux intro 2 basic terminal
Linux intro 2   basic terminalLinux intro 2   basic terminal
Linux intro 2 basic terminal
Giovanni Marco Dall'Olio
 
Malware analysis and forensic analysis of images
Malware analysis and forensic analysis of imagesMalware analysis and forensic analysis of images
Malware analysis and forensic analysis of images
Kyle Taylor
 
Uop pos 433 week 4 file processing commands worksheet new
Uop pos 433 week 4 file processing commands worksheet newUop pos 433 week 4 file processing commands worksheet new
Uop pos 433 week 4 file processing commands worksheet new
ElijahEthaan
 
Use Cases Configuration Manager, proposal
Use Cases Configuration Manager, proposalUse Cases Configuration Manager, proposal
Use Cases Configuration Manager, proposal
frankcastle
 
Basic Unix
Basic UnixBasic Unix
Basic Unix
Rajesh Kumar
 
File accessing modes in c
File accessing modes in cFile accessing modes in c
File accessing modes in c
manojmanoj218596
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02
duquoi
 
File handling in c
File handling in cFile handling in c
File handling in c
mohit biswal
 
Unit 3
Unit  3Unit  3
Unit 3
siddr
 
Introduction to Unix-like systems (Part I-IV)
Introduction to Unix-like systems (Part I-IV)Introduction to Unix-like systems (Part I-IV)
Introduction to Unix-like systems (Part I-IV)
hildenjohannes
 
Unix practical file
Unix practical fileUnix practical file
Unix practical file
Soumya Behera
 
Dill
DillDill

What's hot (18)

Unix system programming
Unix system programmingUnix system programming
Unix system programming
 
Systemcall1
Systemcall1Systemcall1
Systemcall1
 
Linux day 2.ppt
Linux day  2.pptLinux day  2.ppt
Linux day 2.ppt
 
Introduction to linux
Introduction to linuxIntroduction to linux
Introduction to linux
 
4 text file
4 text file4 text file
4 text file
 
Computer Forensics &amp; Windows Registry
Computer Forensics &amp; Windows RegistryComputer Forensics &amp; Windows Registry
Computer Forensics &amp; Windows Registry
 
Linux intro 2 basic terminal
Linux intro 2   basic terminalLinux intro 2   basic terminal
Linux intro 2 basic terminal
 
Malware analysis and forensic analysis of images
Malware analysis and forensic analysis of imagesMalware analysis and forensic analysis of images
Malware analysis and forensic analysis of images
 
Uop pos 433 week 4 file processing commands worksheet new
Uop pos 433 week 4 file processing commands worksheet newUop pos 433 week 4 file processing commands worksheet new
Uop pos 433 week 4 file processing commands worksheet new
 
Use Cases Configuration Manager, proposal
Use Cases Configuration Manager, proposalUse Cases Configuration Manager, proposal
Use Cases Configuration Manager, proposal
 
Basic Unix
Basic UnixBasic Unix
Basic Unix
 
File accessing modes in c
File accessing modes in cFile accessing modes in c
File accessing modes in c
 
intro unix/linux 02
intro unix/linux 02intro unix/linux 02
intro unix/linux 02
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Unit 3
Unit  3Unit  3
Unit 3
 
Introduction to Unix-like systems (Part I-IV)
Introduction to Unix-like systems (Part I-IV)Introduction to Unix-like systems (Part I-IV)
Introduction to Unix-like systems (Part I-IV)
 
Unix practical file
Unix practical fileUnix practical file
Unix practical file
 
Dill
DillDill
Dill
 

Similar to 10

MODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptxMODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptx
ManasaPJ1
 
Chapter4.pptx
Chapter4.pptxChapter4.pptx
Chapter4.pptx
WondimuBantihun1
 
Linux 4 you
Linux 4 youLinux 4 you
Linux 4 you
Shashwat Shriparv
 
File management
File managementFile management
File management
Mohammed Sikander
 
18CS56-UP-Module 3.pptx
18CS56-UP-Module 3.pptx18CS56-UP-Module 3.pptx
18CS56-UP-Module 3.pptx
ChenamPawan
 
Chapter - 5.pptx
Chapter - 5.pptxChapter - 5.pptx
Chapter - 5.pptx
MikialeTesfamariam
 
Python-files
Python-filesPython-files
Python-files
Krishna Nanda
 
File Handling
File HandlingFile Handling
File Handling
AlgeronTongdoTopi
 
File Handling
File HandlingFile Handling
File Handling
AlgeronTongdoTopi
 
Linux Systems Programming: File Handling
Linux Systems Programming: File HandlingLinux Systems Programming: File Handling
Linux Systems Programming: File Handling
RashidFaridChishti
 
Linux basics
Linux basicsLinux basics
Linux basics
sirmanohar
 
02 fundamentals
02 fundamentals02 fundamentals
02 fundamentals
sirmanohar
 
Linux Operating System
Linux Operating SystemLinux Operating System
Linux Operating System
KunalKewat1
 
INput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptxINput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptx
AssadLeo1
 
Module2-Files.pdf
Module2-Files.pdfModule2-Files.pdf
Module2-Files.pdf
4HG19EC010HARSHITHAH
 
Programming Embedded linux
Programming Embedded linuxProgramming Embedded linux
Programming Embedded linux
Liran Ben Haim
 
Introduction to UNIX
Introduction to UNIXIntroduction to UNIX
pointer, structure ,union and intro to file handling
 pointer, structure ,union and intro to file handling pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
Rai University
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
vamsikrishna204239
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
vamsikrishna204239
 

Similar to 10 (20)

MODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptxMODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptx
 
Chapter4.pptx
Chapter4.pptxChapter4.pptx
Chapter4.pptx
 
Linux 4 you
Linux 4 youLinux 4 you
Linux 4 you
 
File management
File managementFile management
File management
 
18CS56-UP-Module 3.pptx
18CS56-UP-Module 3.pptx18CS56-UP-Module 3.pptx
18CS56-UP-Module 3.pptx
 
Chapter - 5.pptx
Chapter - 5.pptxChapter - 5.pptx
Chapter - 5.pptx
 
Python-files
Python-filesPython-files
Python-files
 
File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
Linux Systems Programming: File Handling
Linux Systems Programming: File HandlingLinux Systems Programming: File Handling
Linux Systems Programming: File Handling
 
Linux basics
Linux basicsLinux basics
Linux basics
 
02 fundamentals
02 fundamentals02 fundamentals
02 fundamentals
 
Linux Operating System
Linux Operating SystemLinux Operating System
Linux Operating System
 
INput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptxINput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptx
 
Module2-Files.pdf
Module2-Files.pdfModule2-Files.pdf
Module2-Files.pdf
 
Programming Embedded linux
Programming Embedded linuxProgramming Embedded linux
Programming Embedded linux
 
Introduction to UNIX
Introduction to UNIXIntroduction to UNIX
Introduction to UNIX
 
pointer, structure ,union and intro to file handling
 pointer, structure ,union and intro to file handling pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
 

More from satishbb

9
99
8
88
7
77
5
55
6
66
4
44
3
33
2
22

More from satishbb (8)

9
99
9
 
8
88
8
 
7
77
7
 
5
55
5
 
6
66
6
 
4
44
4
 
3
33
3
 
2
22
2
 

Recently uploaded

EN Artificial Intelligence by Slidesgo.pptx
EN Artificial Intelligence by Slidesgo.pptxEN Artificial Intelligence by Slidesgo.pptx
EN Artificial Intelligence by Slidesgo.pptx
aichamardi99
 
Here's Why Every Semi-Truck Should Have ELDs
Here's Why Every Semi-Truck Should Have ELDsHere's Why Every Semi-Truck Should Have ELDs
Here's Why Every Semi-Truck Should Have ELDs
jennifermiller8137
 
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
MarynaYurchenko2
 
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
78tq3hi2
 
Globalfleet - global fleet survey 2021 full results
Globalfleet - global fleet survey 2021 full resultsGlobalfleet - global fleet survey 2021 full results
Globalfleet - global fleet survey 2021 full results
vaterland
 
Expanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Expanding Access to Affordable At-Home EV Charging by Vanessa WarheitExpanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Expanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Forth
 
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
78tq3hi2
 
AadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) RaipurAadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects
 
Kaizen SMT_MI_PCBA for Quality Engineerspptx
Kaizen SMT_MI_PCBA for Quality EngineerspptxKaizen SMT_MI_PCBA for Quality Engineerspptx
Kaizen SMT_MI_PCBA for Quality Engineerspptx
vaibhavsrivastava482521
 
What Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill Roads
What Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill RoadsWhat Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill Roads
What Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill Roads
Sprinter Gurus
 
EV Charging at Multifamily Properties by Kevin Donnelly
EV Charging at Multifamily Properties by Kevin DonnellyEV Charging at Multifamily Properties by Kevin Donnelly
EV Charging at Multifamily Properties by Kevin Donnelly
Forth
 
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
afkxen
 
Catalytic Converter theft prevention - NYC.pptx
Catalytic Converter theft prevention - NYC.pptxCatalytic Converter theft prevention - NYC.pptx
Catalytic Converter theft prevention - NYC.pptx
Blue Star Brothers
 
What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?
Hyundai Motor Group
 
EV Charging at MFH Properties by Whitaker Jamieson
EV Charging at MFH Properties by Whitaker JamiesonEV Charging at MFH Properties by Whitaker Jamieson
EV Charging at MFH Properties by Whitaker Jamieson
Forth
 
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
afkxen
 
Hand Gesture Control Robotic Arm using image processing.pptx
Hand Gesture Control Robotic Arm using image processing.pptxHand Gesture Control Robotic Arm using image processing.pptx
Hand Gesture Control Robotic Arm using image processing.pptx
wstatus456
 

Recently uploaded (17)

EN Artificial Intelligence by Slidesgo.pptx
EN Artificial Intelligence by Slidesgo.pptxEN Artificial Intelligence by Slidesgo.pptx
EN Artificial Intelligence by Slidesgo.pptx
 
Here's Why Every Semi-Truck Should Have ELDs
Here's Why Every Semi-Truck Should Have ELDsHere's Why Every Semi-Truck Should Have ELDs
Here's Why Every Semi-Truck Should Have ELDs
 
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
 
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
 
Globalfleet - global fleet survey 2021 full results
Globalfleet - global fleet survey 2021 full resultsGlobalfleet - global fleet survey 2021 full results
Globalfleet - global fleet survey 2021 full results
 
Expanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Expanding Access to Affordable At-Home EV Charging by Vanessa WarheitExpanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Expanding Access to Affordable At-Home EV Charging by Vanessa Warheit
 
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
 
AadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) RaipurAadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) Raipur
 
Kaizen SMT_MI_PCBA for Quality Engineerspptx
Kaizen SMT_MI_PCBA for Quality EngineerspptxKaizen SMT_MI_PCBA for Quality Engineerspptx
Kaizen SMT_MI_PCBA for Quality Engineerspptx
 
What Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill Roads
What Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill RoadsWhat Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill Roads
What Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill Roads
 
EV Charging at Multifamily Properties by Kevin Donnelly
EV Charging at Multifamily Properties by Kevin DonnellyEV Charging at Multifamily Properties by Kevin Donnelly
EV Charging at Multifamily Properties by Kevin Donnelly
 
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
 
Catalytic Converter theft prevention - NYC.pptx
Catalytic Converter theft prevention - NYC.pptxCatalytic Converter theft prevention - NYC.pptx
Catalytic Converter theft prevention - NYC.pptx
 
What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?
 
EV Charging at MFH Properties by Whitaker Jamieson
EV Charging at MFH Properties by Whitaker JamiesonEV Charging at MFH Properties by Whitaker Jamieson
EV Charging at MFH Properties by Whitaker Jamieson
 
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
 
Hand Gesture Control Robotic Arm using image processing.pptx
Hand Gesture Control Robotic Arm using image processing.pptxHand Gesture Control Robotic Arm using image processing.pptx
Hand Gesture Control Robotic Arm using image processing.pptx
 

10

  • 1. 18IS33-UNIX and Shell Programming (Scheme and Solution) Page 10 Signature of the QuestionPaperSetter: : Signature of Scrutinizer Subject Titles: UNIX and Shell Programming. Subject Code: 18IS33 Q.No. Solutions Marks Allotted 10.c) File andling To access a file on your UNIX file system from within your Perl program, you must perform the following steps: 1. First, your program must open the file. This tells the system that your Perl program wants to access the file. 2. Then, the program can either read from or write to the file, depending on how you have opened the file. 3. Finally, the program can close the file. This tells the system that your program no longer needs access to the file. To open a file we use the open() function. open(INFILE, /home/srm/input.dat”); INFILE is the file handle. The second argument is the pathname. If only the filename is supplied, the file is assumed to be in the current working directory. open(OUTFILE,”>report.dat”); # Opens the file in write mode open(OUTFILE,”>>report.dat”); # Opens the file in append mode The following script demonstrates file handling in perl. This script copies the first three lines of one file into another. #!/usr/bin/perl open(INFILE, “desig.dat”) || die(“Cannot open file”); open(OUTFILE, “>desig_out.dat”); while(<INFILE>) { print OUTFILE if(1..3); } close(INFILE); close(OUTFILE); 6M