07-31-2002
perl -pi -e
The -i option in Perl will edit the specified file "in place", so you don't have to mess with moving files around.
% echo "eat food" >> test.txt
% echo "eat more food" >> test2.txt
% perl -pi -e 's/food/pie/g' *
% cat test.txt
eat pie
% cat test2.txt
eat more pie
-i takes an optional argument. If specified, a backup will be saved with the argument as the file's extension.
% perl -pi'.bak' -e 's/pie/chicken/g' *
% ls
test.txt test.txt.bak test2.txt test2.txt.bak
% cat test.txt
eat chicken
% cat test.txt.bak
eat pie
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have file which has "A" character in more than 1000 lines and I want replace this "A" with "f". There is also "A" which I don't want to replace at the last line.
Currently, I use this script to replace them one by one
:g/A/s//f/g
Regards (2 Replies)
Discussion started by: mewalter
2 Replies
2. Shell Programming and Scripting
I have a 3 status option 1 , 4 , 6
1 - Active
4 - Temp..
6 - Deactive
I want to build a script which when it finds either of the status options (1,4,6), then returns the relevant string.
txs
:confused: (3 Replies)
Discussion started by: mewalter
3 Replies
3. Shell Programming and Scripting
Hi,
I made a build script for the product I am working on.
The script was made in the /bin/sh shell.
My first line in the script (after the #! /bin/sh and following # lines ) were,
if ; then
/bin/sh
fi;
It works well with my sh shell. I run the script as
sh build.sh
Now I... (9 Replies)
Discussion started by: vino
9 Replies
4. Shell Programming and Scripting
Hi all,
I had a typical problem.
I am using a parameter
PK="PK1 PK2 PK3"
i need to build the string
a.PK1=b.PK1 and a.PK2=b.PK2 and a.PK3=b.PK3
Please help (8 Replies)
Discussion started by: nkosaraju
8 Replies
5. Shell Programming and Scripting
Greets. I have a build system that comprises of one parent script and about 150 children to build Gnome. I have a file that is sourced at the top of every script to gather variables needed for the build. In this variables file, CFLAGS are set.
What I would like to do is do a quick check... (1 Reply)
Discussion started by: madpenguin
1 Replies
6. Shell Programming and Scripting
Hi All
I am trying to build a script that will take data from a tab separated file and use that to split up a quicktime file. So far the code is as follows
#!/bin/sh
#test parsing of data
#fix excel file output returns
cat $1 | tr "\r" "\n" > $1.fix
printf "\n" >> $1.fix
mv $1.fix $1
... (3 Replies)
Discussion started by: babajuma
3 Replies
7. Shell Programming and Scripting
Can someone take a look into script, where and what is going wrong in this. (4 Replies)
Discussion started by: baraghun
4 Replies
8. UNIX for Dummies Questions & Answers
Hi,
So I downloaded this kernel source and was able to build it successfully.
But I want to add this SDK source code inside, can anyone help me how to do this? Note that the SDK source can be built by itself.
I added the SDK in the main Makefile:
init-y := init/
#added SDK... (0 Replies)
Discussion started by: h0ujun
0 Replies
9. Shell Programming and Scripting
Hi
I have a build.xml file and I can run it on Windows via cmd. Now I want to write a script to invoke the same. Is there a way to do this? (1 Reply)
Discussion started by: ankur328
1 Replies
10. Shell Programming and Scripting
Okay, so this one is a bit above my knowledge level so I'm hoping for some pointers.
Here's the scenario:
I have a backup system on my network that makes single file images of the machines it's backing up and uses an sqlite database to keep track of everything. As is pretty typical with... (2 Replies)
Discussion started by: NyxPDX
2 Replies
LEARN ABOUT PHP
ziparchive.open
ZIPARCHIVE.OPEN(3) 1 ZIPARCHIVE.OPEN(3)
ZipArchive::open - Open a ZIP file archive
SYNOPSIS
mixed ZipArchive::open (string $filename, [int $flags])
DESCRIPTION
Opens a new zip archive for reading, writing or modifying.
PARAMETERS
o $filename
- The file name of the ZIP archive to open.
o $flags
- The mode to use to open the archive.
o ZipArchive::OVERWRITE
o ZipArchive::CREATE
o ZipArchive::EXCL
o ZipArchive::CHECKCONS
RETURN VALUES
o $Error codes
- Returns TRUE on success or the error code.
o ZipArchive::ER_EXISTS File already exists.
o ZipArchive::ER_INCONS Zip archive inconsistent.
o ZipArchive::ER_INVAL Invalid argument.
o ZipArchive::ER_MEMORY Malloc failure.
o ZipArchive::ER_NOENT No such file.
o ZipArchive::ER_NOZIP Not a zip archive.
o ZipArchive::ER_OPEN Can't open file.
o ZipArchive::ER_READ Read error.
o ZipArchive::ER_SEEK Seek error.
EXAMPLES
Example #1
Open and extract
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
echo 'ok';
$zip->extractTo('test');
$zip->close();
} else {
echo 'failed, code:' . $res;
}
?>
Example #2
Create an archive
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFromString('test.txt', 'file content goes here');
$zip->addFile('data.txt', 'entryname.txt');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
PHP Documentation Group ZIPARCHIVE.OPEN(3)