01-15-2007
grep and delete ONE only
Hi,
I have a txt file will a lot of data...however, some of them a duplicated and I would like to remove it. Normally, I need to edit txt and delete it. But it take a lot of time to do....
filename.txt:
orange
apple
cake
pink
apple
if using grep -v 'apple' filename.txt > new_filename.txt, it will remove all 'apple' and I just want to delete 2nd 'apple'.
anyone can help?
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I find out one problem is...the main point is we must delete 2nd duplicated of word in txt file. For example
apple
orange
pink
green
orange
yellow
orange
red
output should be:
apple
orange
pink
green
yellow
orange (16 Replies)
Discussion started by: happyv
16 Replies
2. Shell Programming and Scripting
Hi
I am writing a script which should read a file and search for certain strings 'approved' or 'removed' and retain only those lines that contain the above strings.
Ex: file name 'test'
test:
approved package
waiting for approval package
disapproved package
removed package
approved... (14 Replies)
Discussion started by: vj8436
14 Replies
3. Shell Programming and Scripting
Hi,
i need to delete a lines after searching a particular string but this searching should only happen after the 4th line..
basically imagine a file like this
From: abcd.yahoo.com
To: cdeb.yahoo.com
Subject: hi all
sdfsd
sadasd
asdasd
dfsdf
From: abcd.yahoo.com
To:... (3 Replies)
Discussion started by: depakjan
3 Replies
4. Shell Programming and Scripting
I'm new to using sed and grep commands, but have found them extremely useful. However I am having a hard time figuring this one out:
Delete every line containing the word CEN and the next line as well.
ie. test.txt
blue
324 CEN
green
red
blue
324 CEN
green
red
blue
to produce:... (2 Replies)
Discussion started by: rocketman88
2 Replies
5. Shell Programming and Scripting
Hi,
1_strings file contains
$ cat 1_strings
/home/$USER/Src
/home/Valid
/home/Review$ cat myxml
<projected value="some string" path="/home/$USER/Src">
<input 1/>
<estimate value/>
<somestring/>
</projected>
<few more lines >
<projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies
6. Shell Programming and Scripting
Hi everyone, thank you so much for reading.
I built a user reference page from /etc/password for a class project. Now I need two shell scripts: 1) Add names to the reference page 2) Delete names from the reference page. I know grep -v is involved somehow and some piping but I am super stuck.
... (1 Reply)
Discussion started by: jsmpdx
1 Replies
7. Shell Programming and Scripting
here is what i want to achieve.. i have a file with below contents
cat fileName
blah blah blah
.
.DROP this
REJECT that
.
--sport 7800 -j REJECT --reject-with icmp-port-unreachable
--dport 7800 -j REJECT --reject-with icmp-port-unreachable
.
.
.
more blah blah blah
--dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies
8. Shell Programming and Scripting
i have this line of code that looks for the same file if it is currently running and returns the count.
`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`
basically it is assigned to a variable
ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies
9. Shell Programming and Scripting
Hi
My directory structure is as below.
dir1, dir2, dir3
I have the list of files to be deleted in the below path as below.
/staging/retain_for_2years/Cleanup/log $ ls -lrt
total 0
drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2
drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies
10. Shell Programming and Scripting
Hi All,
OS: Redhat Linux 7.5
Shell: Bash
I have some folder like this
2018-09-16
2018-09-17
2018-09-18
2018-09-19 and so on...
Everyday one script create a folder with pattern YYYY-MM-DD (it will have so many sub directories files in it)
Now what I would like to achieve is a... (1 Reply)
Discussion started by: onenessboy
1 Replies
LEARN ABOUT PHP
ziparchive.addfile
ZIPARCHIVE.ADDFILE(3) 1 ZIPARCHIVE.ADDFILE(3)
ZipArchive::addFile - Adds a file to a ZIP archive from the given path
SYNOPSIS
bool ZipArchive::addFile NULL (string $filename, [string $localname], [int $start], [int $length])
DESCRIPTION
Adds a file to a ZIP archive from a given path.
PARAMETERS
o $filename
- The path to the file to add.
o $localname
- If supplied, this is the local name inside the ZIP archive that will override the $filename.
o $start
- This parameter is not used but is required to extend ZipArchive.
o $length
- This parameter is not used but is required to extend ZipArchive.
RETURN VALUES
Returns TRUE on success or FALSE on failure.
EXAMPLES
This example opens a ZIP file archive test.zip and add the file /path/to/index.txt. as newname.txt.
Example #1
Open and add
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
$zip->addFile('/path/to/index.txt', 'newname.txt');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
NOTES
Note
When a file is set to be added to the archive, PHP will lock the file. The lock is only released once the ZipArchive object has
been closed, either via ZipArchive::close or the ZipArchive object being destroyed. This may prevent you from being able to delete
the file being added until after the lock has been released.
PHP Documentation Group ZIPARCHIVE.ADDFILE(3)