09-02-2008
Replacing contents in a file from multiple programmes
Hi All,
I have a query on Perl. I have a text file which has 3 lines, i want to only replace the first line with my replaced text and keep the rest of the text. FOr eg
Before change -->
echo:a
ending
echo
pending
echo:c
ending
After change --->
echo:a:done
echo
pending
echo:c
ending
Brief: Here i am continuously trying to modify the text file though this perl programme from multiple machines i.e this perl prog will run on multiple machines trying to modify\change a single text.
Snippet of my code.(not working yet. It appends to the text file instead of replacing it). Can you please guide me to this.
============================================
open(MYFILE, "+< $myfile") || die;
flock(MYFILE, 2);
#my $myfile="c:\\ssk\\help.txt";
#open INPUT, "<$myfile";
undef $/;
my $content = <MYFILE>;
my $inprogress = "inprogress";
my $done = "done";
$content =~ m/(\w*)
\w*)
\w*)/;
if ($3 eq "pending")
{
$content=~ s/pending/inprogress/;
my $contentbkup = $content;
$content =~ s/(.*)//g;
print MYFILE "$1";
print MYFILE "$contentbkup";
$contentbkup =~ s/(.*)
.*)
.*)/(.*)
.*):$done/;
}
seek(MYFILE, 0, 0);
close MYFILE;
$/ = "\n";
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have a file that contains the following lines
the brown quick fox
jumped over
the white laze dog
0123456789
I wanted to put the contents of this file into a variable so I used this code:
VAR_LIST=`cat $2`
where $2 is the file name passed as an argument to the script
If I... (3 Replies)
Discussion started by: Nomaad
3 Replies
2. Shell Programming and Scripting
I'm trying to change the ramfs size in kernel .config automatically.
I have a ramfs_size file generated with du -s
cat ramfs_size
64512
I want to replace the linux .config's ramdisk size with the above value
CONFIG_BLK_DEV_RAM_SIZE=73728
Right now I'm doing something dumb like: ... (3 Replies)
Discussion started by: amoeba
3 Replies
3. Shell Programming and Scripting
Hi,
I have a set of files stored in a single directory that I use to set parameters for a physics code, and I would like to streamline the process of updating them all when I change a parameter. For instance, if the files are called A2000p300ini, A2000p300sub, A2000p300run, and the text in each... (3 Replies)
Discussion started by: BlueChris
3 Replies
4. Shell Programming and Scripting
Being new to this area .I have been assigned a task which i am unable to do . Can any one please help me .
Hi I have requirement where i have input file XYZ_111_999_YYYYMMDD_1.TXT and with header and series of Numbers and Footer.
I want to create a mutiple output files with each file having a... (2 Replies)
Discussion started by: bhargavkr
2 Replies
5. Ubuntu
Hi!
I have installed ubuntu out of an error, a bit of frustration, a bit of annoyance and a bit of excitement! I am (was!) a windows user. I had windows 7 on my laptop. You might already know how famous windows is with nasty viruses. I got one too! Had no option but to get rid of the whole... (3 Replies)
Discussion started by: ubuntu_noob
3 Replies
6. Shell Programming and Scripting
We have 2 file XML files - FILE1.XML and FILE2.xml - we need copy the contents of FILE1.XML and replace in FILE2.xml pattern "<assignedAttributeList></assignedAttributeList>"
FILE1.XML
1. <itemList>
2. <item type="Manufactured">
3. <resourceCode>431048</resourceCode>
4. ... (0 Replies)
Discussion started by: balrajg
0 Replies
7. UNIX for Dummies Questions & Answers
I need to replace all filesnames in a folder as well as its content from AK6 to AK11. Eg Folder has files AK6-Create.xml, AK6-system.py etc.. the files names as well as contents should be changes to AK9-Create.xml, AK9-system.py etc
All files are xml and python scripts.
---------- Post... (0 Replies)
Discussion started by: Candid247
0 Replies
8. Shell Programming and Scripting
Hi
Am confused with the usage of "sed" command
I want to replace a single line with multiple lines of a file..
eg.,
A file has
Hi, How are you?
I need to replace as
Am fine
What are You doing?
I used the script as
string1="Hi, How are you?"
echo "$string1 is the value"... (4 Replies)
Discussion started by: Priya Amaresh
4 Replies
9. Shell Programming and Scripting
Greetings all
I have a delimited text file (the delimiter is ';') where certain fields consist of many blanks e.g. ; ; and ; ;
Before I separate the data I need to eliminate these blanks altogether.
I tried the sed command using the following syntax:
sed -i 's/; *;/;;/g' <filename>
... (15 Replies)
Discussion started by: S. BASU
15 Replies
10. UNIX for Beginners Questions & Answers
I am trying to consolidate multiple information files (<hostname>.Linux.nfslist) into one file so that I can import it into Excel. I can get the file contents with cat *Linux.nfslist >> nfslist.txt. I need each line prefaced with the hostname. I am unsure how to do this.
--- Post updated at... (5 Replies)
Discussion started by: Kentlee65
5 Replies
LEARN ABOUT PHP
numberformatter.gettextattribute
NUMBERFORMATTER.GETTEXTATTRIBUTE(3) 1 NUMBERFORMATTER.GETTEXTATTRIBUTE(3)
NumberFormatter::getTextAttribute - Get a text attribute
Object oriented style
SYNOPSIS
public string NumberFormatter::getTextAttribute (int $attr)
DESCRIPTION
Procedural style
string numfmt_get_text_attribute (NumberFormatter $fmt, int $attr)
Get a text attribute associated with the formatter. An example of a text attribute is the suffix for positive numbers. If the formatter
does not understand the attribute, U_UNSUPPORTED_ERROR error is produced. Rule-based formatters only understand NumberFormat-
ter::DEFAULT_RULESET and NumberFormatter::PUBLIC_RULESETS.
PARAMETERS
o $fmt
-NumberFormatter object.
o $attr
- Attribute specifier - one of the text attribute constants.
RETURN VALUES
Return attribute value on success, or FALSE on error.
EXAMPLES
Example #1
numfmt_get_text_attribute(3) example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
echo "Prefix: ".numfmt_get_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX)."
";
echo numfmt_format($fmt, -1234567.891234567890000)."
";
numfmt_set_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX, "MINUS");
echo "Prefix: ".numfmt_get_text_attribute($fmt, NumberFormatter::NEGATIVE_PREFIX)."
";
echo numfmt_format($fmt, -1234567.891234567890000)."
";
?>
Example #2
OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL );
echo "Prefix: ".$fmt->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX)."
";
echo $fmt->format(-1234567.891234567890000)."
";
$fmt->setTextAttribute(NumberFormatter::NEGATIVE_PREFIX, "MINUS");
echo "Prefix: ".$fmt->getTextAttribute(NumberFormatter::NEGATIVE_PREFIX)."
";
echo $fmt->format(-1234567.891234567890000)."
";
?>
The above example will output:
Prefix: -
-1.234.567,891
Prefix: MINUS
MINUS1.234.567,891
SEE ALSO
numfmt_get_error_code(3), numfmt_get_attribute(3), numfmt_set_text_attribute(3).
PHP Documentation Group NUMBERFORMATTER.GETTEXTATTRIBUTE(3)