Sponsored Content
Top Forums Shell Programming and Scripting Perl : how to modify a file without generate a temporary file Post 302442247 by summer_cherry on Tuesday 3rd of August 2010 09:59:29 PM
Old 08-03-2010
thanks, but still more help needed

thanks very much for your reply.
with inplace file edit, it is ok for this easy case.
but my requirement is a little bit complicated:

1> rather than directly insert lines in original file, still need to open file to read and check some key word

2> if key words found, print the key words

3> if key words not found, insert into file

example

original file
Code:
[books]
java = 30$
oracle = 20$
[tools]
Ultraedit = 100$
Eclipse = 200$


supposed the perl script is named as conf.pl, -s option is for section, -k option is for key, -v option is for value

Code:
1> conf.pl -s books -k java
    print 30$

2> conf.pl -s books -k perl -v 40$
    append line 
    perl = 40$ 
    after line 
    oracle = 20$

3> conf.pl -s cds -k english -v 100$
    append 
    [cds]
    english = 100$


So basically the case is modify file content on hot at any time if meet or not-meet any condition.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modify script to generate a log file

I've seen several examples of scripts in thise forum about having a script generate a log file. I have a script that is run from cron and that monitors a file system for a specfic filename(s) and then performs some actions on them. Normally I call this script from another script (which the one... (2 Replies)
Discussion started by: heprox
2 Replies

2. Shell Programming and Scripting

remove temporary file ?

Hi all, In the script I am creating a temporary file with process id as temp.txt.$$ I want to remove this tomporary file first from the current directory when i'll run the same script next time. Note: Every time when the script executes then it has unique process id and it'll create a... (5 Replies)
Discussion started by: varungupta
5 Replies

3. Shell Programming and Scripting

Need help to modify perl script: Text file with line and more than 1 space

Dear Friends, I am beginner in Perl and trying to find the problem in a script. Kindly help me to modify the script. My script is not giving the output for the last field and followed text (LA: Language English). Input file & script as follows: Input file: Thu Mar 19 2:34:14 EDT 2009 STC... (3 Replies)
Discussion started by: srsahu75
3 Replies

4. Shell Programming and Scripting

temporary file to file then move to directory

Ok in my bash script i have 5 options to create a simple html script. I need to create a temporary file and whatever the user types will be stored in that file using html codes. And then I have another option in which that temporary file will be moved to the public_html directory in which the user... (19 Replies)
Discussion started by: gangsta
19 Replies

5. Shell Programming and Scripting

How to remove the first line of a file without using any temporary file

I want remove first line of the file without using any temporary file. Everything should be done in the original file itself since I don't any file creation access whereas I have modify access. It would be great if somebody help in this regard ASAP . Thanks in Advance. Kishore:mad: (1 Reply)
Discussion started by: tvbhkishore
1 Replies

6. Shell Programming and Scripting

Modify the file with awk,sed or perl

Hi All, I need help from any of you.Would be so thankful for your help. I/P DDDD,1045,161,1557,429,1694,800,1911,1113,2460,1457,2917> 1609,3113,1869,3317,2732,3701,3727,4132,5857,5107> 9004,6496 DDDD,1125,157,1558,429,1694,800,1911,1117,2432,1444,2906>... (2 Replies)
Discussion started by: Indra2011
2 Replies

7. Shell Programming and Scripting

Perl script to modify csv file

Hi Friends, I want to convert a csv file into a ordinary .txt file. I am able to convert but I want the output to look as shown below in the .txt file table findhost= { {"xyz","abc"}, {"rxz","mmz"}, {"vrr","nnz"}, } default={"NONE"} My current perl script #!/usr/bin/env perl... (12 Replies)
Discussion started by: dbashyam
12 Replies

8. UNIX for Dummies Questions & Answers

Mailx - temporary mail message file: No such file or directory

How would I go about resolving this error temporary mail message file: No such file or directory Can anybody tell me where the default location is for the temporary mail message file is for mailx? It appears that it doesn't exist. Thanks (1 Reply)
Discussion started by: joen
1 Replies

9. Programming

Storing a Temporary File Using C

How would someone save a file such as /etc/vpnc/test.conf locally into a temp file, so it can be queried? So for example if I used rsync to copy this file locally, how would I add that to a temp_file variable and discard it using unlink? #include <stdio.h> #include "error.h" ... (15 Replies)
Discussion started by: metallica1973
15 Replies

10. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies
PW_GETCONF(3)						   BSD Library Functions Manual 					     PW_GETCONF(3)

NAME
pw_getconf, pw_getpwconf -- password encryption configuration access function LIBRARY
System Utilities Library (libutil, -lutil) SYNOPSIS
#include <util.h> void pw_getconf(char *data, size_t len, const char *key, const char *option); void pw_getpwconf(char *data, size_t len, const struct passwd *pwd, const char *option); DESCRIPTION
The pw_getconf() function reads /etc/passwd.conf and retrieves the value of the option specified by option from the section given by key. If no suitable entry is found for the key an empty string will be returned in data. To retrieve default values the key default can be used. In this case, if /etc/passwd.conf does not exist or does not contain a default sec- tion, the built-in defaults will be returned. They are as follows: option data ypcipher old localcipher old An empty string is returned for all errors. pw_getpwconf() returns the value for the option specified for the particular user specified in pwd. If that option is not found, then it tries to find the option in the primary group of that user, and if that fails, then it returns the default entry. FILES
/etc/passwd.conf ERRORS
pw_getconf() and pw_getpwconf() will fail if: [ENOENT] There is no option named option in the specified key. [ENOTDIR] There is no key in /etc/passwd.conf named key. SEE ALSO
passwd(5), passwd.conf(5) HISTORY
The pw_getconf() function first appeared in NetBSD 1.6. BSD
May 4, 2010 BSD
All times are GMT -4. The time now is 10:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy