Programming :: Bash - Delete Only One Line From A File?
Apr 9, 2011
I would like to delete a single line from a file that contains many lines passing through the same values as the two parameters. Again, I would like to delete a single line and not all those that contain parameters. How can I make bash?
View 14 Replies
ADVERTISEMENT
Apr 1, 2009
Was wondering if any perl guru's could help me with a quick log file adjustment. I have a text file that looks like so (tabs and newlines are revealed so you can see what separates the data):
There are maybe 100 lines of text in this file at any given time. I need to delete all duplicate lines only looking at the first bit of text prior to the first tab. It doesn't matter which one gets deleted as long as there are no two lines that begin with that same text at the beginning before the first tab. So in this example, either the fist line "1234" or the last line "1234" would need to be deleted. I already have code in my script that opens the files - I just need the code to read the text into an array and the part that would find matches based on the above criteria, and make the deletions.
If it would be easier, I can even do a system call and use SED (v4.1.5) and/or AWK (3.1.5) instead.
View 7 Replies
View Related
Jul 7, 2011
bash 3.1.17(2) I'm trying do write a shell script which must operate on each line of an ASCII text file. So, all the code must be inside a loop, and inside the loop, the first thing should be to read the next line from the file. I have the bash read command. But it reads from stdin. Any way to make read from a file?
View 6 Replies
View Related
Oct 13, 2010
I want to delete lines which contain the word "Fehler" but for some reason my programm isn't working:
Code: BEGIN { FS="|"
OFS="|"
SUBSEP="|"
[code]...
View 6 Replies
View Related
Oct 16, 2010
i have a file containing contents as
1 2 3
2 2 3
11 2 3
now i want to delete the line which first column content is 1. so, if i pass the parametere 1 to function delete_row. is should remove the first row as
2 2 3
11 2 3
and then write the contents in file.
View 2 Replies
View Related
Jan 26, 2010
Quote:Originally Posted by topcatI would like to know how i can write a shell script to delete a line if a particular pattern exists?E.g. I have a text file with multiple lines. Say 1000s. in the following pattern.
username@email.com:149.0.3.4:1
username1@email.com:149.0.3.4:1
username1@email.net:149.0.3.4:1
username1@email.edu:149.0.3.4:1
If the patternusername@email.com exists then the line "username@email.com:149.0.3.4:1 should be deleted from the file.I have a very similar question but I need to delete one line in a file which matches one very precise instance of a string only. Let's assume I have a file composed of thousands of lines and let's call the file chap-secrets. Let's take the following sample entries:
Code:
#USERNAME SERVER PASSWORD IP
pp pptpd blahblah *
[code]....
View 7 Replies
View Related
Mar 24, 2010
Below is the part of my bash script which uses awk to to fetch a line from a file. Choice is set by a case, and i know it is receiving a proper number because of the echo statement. The problem is with the syntax of the awk command it says the error is with one of the ', but when I run the command at the command line and replace "$choice" with a number it works properly. So I am not sure what is going on.
echo "announcing choice $choice"
command="awk 'NR = "$choice"' beerpong.txt | say"
$command
View 8 Replies
View Related
Apr 23, 2011
I've got a bash script I'm using to download a text file list of links via axel. What I'd like to do is automate the movement of completed links in the for loop when axel has successfully completed the download. This is what I've got. I can figure that I can just echo append the line to a new file, but what is the easiest way to delete the line with the link I just downloaded?
Code:
#!/bin/bash
for i in $( cat $1); do
axel --alternate --num-connections=6 $i
export RC=$?
[code]....
View 14 Replies
View Related
Feb 15, 2011
At the moment I got my md5sum checking working which I write to a text file and see below.
If the md5sum works it will write the output to check2.md5 test.txt: OK
If the md5sum fails it will write test.txt: FAILED
How do I write if statement to check the output whether or not the md5sum failed or not ?
check1="/home/ops/Desktop/test1/check1.md5"
check2="/home/ops/Desktop/test1/check2.md5"
cd /home/ops/Desktop/test1
md5sum test.txt > $check1
[Code]....
View 2 Replies
View Related
Dec 8, 2010
I have grepped a log file to obtain every line that contains a word (let's call it 'blah'). I now want to only display a list of entries within that search result that feature the word 'host' anywhere in the line, and I also want to display the single word *after* 'host' (up until the next space). So, the end result will look like this:
[Code]....
View 8 Replies
View Related
Jan 26, 2011
I'm having issue when trying to change a line in a file
[Code]....
View 1 Replies
View Related
Jul 22, 2011
I am trying to write a bash script that installs a program fully automated for me. I am stuck at the one part where i need to change a line in one config file. I have tried various syntax for sed and none have worked. Maybe someone can suggest how to go about this. Since the line appears in the middle of the file, I can't use echo or cat. Also the file will be diffrent lengths depending on the install.
The line I need changed is:
I need that changed to:
the last syntax i tried is:
Yes this is for PNP4Nagios on centos 5.6 64bit. If i can get this figured out. I will be willing to post the whole thing for others to use. it will be used to install PNP after a working nagios install is done.
View 11 Replies
View Related
Jan 13, 2010
I have to delete a certain line of text from the a textfile via ubuntu's shell scripting.I have done research, and it seems that most people advocate the usage of sed /d option. sed makes does not edit the text file. Hence, most options I discovered involved the use of a temporary variable/textfile and then overwriting the old file with the temporary new file. Is there anyway whereby I can bypass the use of temporary storage containers? I hope there is any magical combination of commands to edit the file directly.
View 3 Replies
View Related
Sep 12, 2010
I currently have 3 files with floating point data that I wish to have in a single file with the format:
Code:
F1 F1 F3 Output
a1 b1 c1 a1 b1 c1
a2 b2 c2 a2 b2 c2
a3 b3 c3 a3 b3 c3
a4 b4 c4 a4 b4 c4
View 3 Replies
View Related
Feb 4, 2011
I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.
View 3 Replies
View Related
Mar 8, 2011
I have a set of files containing data that I need to re-arrange into one single property list.
The files that I have look like this:
Code:
# cat uk
<string>10</string>
<string>11</string>
...
<string>29</string>
[Code]....
So the lines in the files match up but I haven't found a way of reading several files line by line.
View 3 Replies
View Related
Aug 18, 2010
I'm trying to make another file annotation script a little speedier than it has been by the up-until-now proven method of checking the last four characters in a filename before the "dot" (eg .jpg, .psd) against a list of known IPTC categories and Exiv2 command files. It occurred to me that if one script generated a list of files in directory foo, and the same or another script sorted that list by that four-letter tag,then that list could be used(instead of a for/do/done loop on the real files in the folder) by the command-file-matching script to "vomit out" which annotator file would go with file nastynewfile.jpg, f'r'instance. The script I had been using for this task looks like this:
Code:
while read 'line';
do
sp=$(echo $line)
vc=$(echo $sp | cut -d"," -f1)
cv=$(echo $sp | cut -d"," -f2)
[code]....
Where I seem to be stuck is with how to sort the lines in templist, which may be any number of different lengths, from back to front. sort -k looked promising, except it seems only to work the other way round. I thought of invoking a
Code:
q=$(expr length $line); echo $q
n=$[q-8]; echo $n
kind of thing, but that presented the problems of how to sort by those, how to tell sort where to find them (grep?) and how to "stitch them back in" to the original list, which is what I want to sort in the first place.
View 14 Replies
View Related
Jan 10, 2011
I have a wrapper script called MAIN.sh that runs several other script. It looks like this:
Code:
#! /bin/sh
script1.sh
[code]...
View 6 Replies
View Related
Nov 29, 2010
I have a text file (myfile.txt) with columns a,b,c.
123 2 23
124 2 24
125 2 22
[code]...
View 4 Replies
View Related
Feb 13, 2011
I want to access a file, and check the length of every line.After, i want to check and replace all lines with length over 10 characters, with a message.Does anyone have a clue on that?
View 1 Replies
View Related
Apr 1, 2011
if the given pattern exists in the file with the very next line starting and endingwith the same pattern , delete the line that starts and ends with the given pattern.So upon running on this file
hai people<PATTERN> we had
<PATTERN>a lot of fun<PATTERN>
writing scripts
[code]....
View 6 Replies
View Related
Aug 4, 2010
Delete this with maximum prejudice, mods.
View 1 Replies
View Related
Mar 27, 2011
I have a question about sed programming, actually a one-liner for which I cannot find a solution, right now. I need to delete a line matching a specific pattern only if it is the last line. In practice, I would put together the following:
Code:
#
# This deletes the last line of a file
[code]...
View 5 Replies
View Related
May 23, 2011
I would like to combine two arrays and delete duplicates that might occur. I tried to solve it like this:
Code:
combined=( "${results1[@]}" "${results2[@]}" )
printf "${combined[@]}" | sort -n | uniq
Example:
result1 (4 elements):
[Code]....
In my code printf seems to have a problem with elements that have the same letters but a space inbetween. For instance "new foo", "newfoo" are the same for printf
View 5 Replies
View Related
Mar 3, 2010
I have a log file /var/log/messages. Now all i want is to delete the first line through script without disturbing provisioning the file.
View 1 Replies
View Related
Nov 11, 2010
I was creating a few scripts, I am trying to create a restore script to restore files that have previously been moved to a folder I selected. When moved I stored the original path for these files all in one text file.
I want to know if anyone can tell me how to delete the line from the file after using it restore the file. I have used the grep command to search through the file "pathName" to find where the file was stored but now want to delete that same line.
View 5 Replies
View Related
Dec 8, 2010
I prefer to delete trailing slahes from pathes. Until now I used sed:
Code: $ myPath=/home/ladygaga///
$ echo "$myPath" | sed 's//*$//'
/home/ladygaga I played around to accomplish the same with on-board means of bash without using sed, but for example this line only deletes one trailing slash:
Code: $ myPath=/home/ladygaga///
$ echo ${myPath%/*}
/home/ladygaga// Is there a way to delete trailing slahes with just on-board means of bash?
View 2 Replies
View Related
Mar 3, 2010
I have a log file which is continously being accessed. Now I want to delete the first line without disturbing the file.Is it possible? The Issue is the log file is being provisioned with ^@^@^@ characters in the first line occupying huge space.So I need to get rid of that. I dont have time to work with root cause but just a script to reduce this space.
View 3 Replies
View Related
Mar 27, 2011
In a bash shell script, I want to do something like this:
Code:
if [[ $(ls -ld /some/dir/foo_* | wc -l) -gt 4 ]]; then
rm -rf first_match_of /some/dir/foo_*
[code]....
View 6 Replies
View Related
Mar 31, 2011
What's a Unix/Linux one-liner that will let me delete all but the most recent N revisions of each file?
I've got a bunch of files with revision numbers as part of a legacy asset-management system:
bar.r7.js
bar.r8.js
bar.r9.js
bar.r10.js
bar.r11.js
[Code]....
I want to keep the last three of each, so in the above list the command would delete bar.r7.js, bar.r8.js and foo.r1.js.
View 1 Replies
View Related