General :: Conditionally Deleting Lines From File

Mar 10, 2011

I am facing some problem regarding deletion of a line from a text file. The file consists of the lines of type which consists of more than 6 occurrences of : character in it. The line should be deleted completely and the line next to it must be shifted up.

View 1 Replies


ADVERTISEMENT

Programming :: Deleting Lines From A File With Specific Pattern Using AWK?

Jun 6, 2010

I have a file which contains milion of records. It contains 12 columns seperated by "||" (delimeter).

First two fields contain first name and last name of a person. Now my requirement is to delete all those records from this file for which:

First two fields does not contain any alphabet.

For e.g i have below mentioned records in file:

gaurav||gandhi||123||456||789
#a%bcd||123abc||89|90||91
12345||@@@||89||123||234
***||!!!!||98||76||90

Now, last two lines should be removed from this file since first two fields does not contain any alphabet for these two records.

View 12 Replies View Related

Programming :: Deleting Multiple Lines Above And Below Expression In File

May 19, 2010

I have a very, very large log file (360MB) that I'm trying to thin out. As it turns out the majority of this file has entries that aren't necessary so I'm attempting to build a command that will strip these out. The following command works to display only the data that I do not want:

Code:
cat xml_results.log | grep -B 6 -A 5 "YYY ZZZ"

This displays exactly the data I want to delete from the file by displaying the expression and six lines above it and five lines below it. However I'm at a loss as to how to remove this data from the output and display everything else. I looked into the -v option with grep redirecting the output to a new file:

Code:
cat xml_results.log | grep -B 6 -A 5 -v "YYY ZZZ" > xml_filtered_results.log

However it doesn't work, the new file is the same size as the old one. What am I doing wrong? Is there a better method of doing this? I'm a bit out of my element since the method I'd normally use can't handle files of this size.

View 7 Replies View Related

General :: Deleting Several Lines In Vim?

Mar 5, 2011

I've a big text, and I would like to delete several lines in vim. I was thinking in doing that with marks, but I can't do it. Below it's an example text and I want to delete from <FROM HERE> to <TO HERE>. How can I do that?
[Quote] .....

View 3 Replies View Related

General :: Deleting Lines From Text Files

Sep 17, 2009

Is there anyway to delete certain paragraphs within a text file and then insert the paragraph into another text file.I just cannot figure out how to remove the specific lines from the file and then insert them into another file at a certain line within that new file. Thanks again

View 10 Replies View Related

General :: Deleting First Line With Unique String Then All Subsequent Lines Thereafter?

Jan 20, 2011

I am doing molecular dynamics where I have to edit files. I have looked at tutorials for grep and sed but can't find my solution. The files produced in my simulations look something like this:

ATOM 1825 NE2 GLN 112 113.646 27.895 14.456
ATOM 1826 HE21 GLN 112 114.020 26.957 14.490
ATOM 1827 HE22 GLN 112 112.649 28.039 14.388

[code]...

View 5 Replies View Related

Fedora :: Conditionally Replace An HTML Tag In A Large File?

Mar 28, 2011

We receive this large file which is generated as a HTML page.So anybody can view it with a web brower.A few lines from this file ...

Code:
<tr><td><font color="#555555" size="3" face="Tahoma, Arial, Verdana, Helvetica"> 1999 <font color="#cc6600" size="5">←</font> <font color="#0066ff" size="4">03</font>-27

[code]...

View 8 Replies View Related

General :: Replace Several Lines In A File With Other Lines In Another File?

Oct 26, 2009

I have this massive table file with some data in it and I want to replace some lines that are wrong with the correct ones that are in another table file of the same format. The wrong lines are not all together in a block but randomly distributed so I need to make a loop checking if the line is in the other file and if it is, replace it. I want to try and do it with sed or awk but I don't really know how to....

View 12 Replies View Related

Programming :: Deleting Lines Above And Below A Word

Mar 25, 2011

i jst want to delete a host entry from httpd.conf the entry for lal.com should be deleted!!

View 14 Replies View Related

General :: How To Recode To UTF-8 Conditionally

Mar 6, 2010

I'm unifying the encoding of a large bunch of text files, gathered over time on different computers. I'm mainly going from ISO-8859-1 to UTF-8. This nicely converts one file:recode ISO-8859-1..UTF-8 file.txtI of course want to do automated batch processing for all the files, and simply running the above for each file has the problem that files whose already encoded in UTF-8, will have their encoding broken. (For instance, the character originally in ISO-8859-1 will appear like this, viewed as UTF-8, if the above recode is done twice:My question is, what kind of script would run recode only if needed, i.e.

only for files that weren't already in the target encoding (UTF-8 in my case)?From looking at recode man page, I couldn't figure out how to do something like this. So I guess this boils down to how to easily check the encoding of a file, or at least if it's UTF-8 or not.This answer implies you could recognise valid UTF-8 files with recode, but how?

View 3 Replies View Related

General :: Conditionally Change Group ID ?

Jan 27, 2011

I have a set of files that have a group ID number where no group exists in the system with that number.

I want to recursively read the group IDs of all (including hidden) files in the current and sub-dirs, test each file's group ID, and if it equals the search GID number, I want to execute a chgrp command on that file.

Anyone have an admin script already made for this task?

View 5 Replies View Related

General :: Deleting A File Beginning With '?'

Jan 26, 2010

I have found a file beginning with a question mark in my home dir, not sure how the hell it got there. It's from a downloaded rar i think.

Does anyone know how to do this?

View 14 Replies View Related

General :: Script To Insert Number Of Lines In A File To The Start Of The File?

Sep 17, 2009

I'm looking for a way to insert the number of lines in a file to the start of the aformentioned file. This should be simple but as I am not used to scripts in Linux, I am finding it tough going. I can find the number of lines in a file easily enough via

filesize=$(awk 'END {print NR}' $1)

but as for inserting this into the first line, i'm failing to do so. I've tried some of the other approaches on these forums but none so far have been able to do so.

I've tried:

sed '1i$filesize' $1

but sed i requires a string, not a variable so no go I've also tried:

mv "$1" "${1}.bak" 2>/dev/null || touch "${1}.bak"
cat $filesize "${1}.bak" >"$1"

but again with no luck as cat seems to need an input stream Just to recap, i want to insert a line at the start of a given file that holds the number of lines the original file has.

ie the file:

a
b
c
d
e

should become:

5
a
b
c

[code].....

View 3 Replies View Related

General :: View A Particular Ten Lines In A Large File Where Can't Open The File In Vi

May 12, 2010

I am using RHEL 5.I have a very large test file which cannot be opened in vi.The content of the file has some 8000 lines.I need to view ten lines between 5680 to 5690.How can i view these particular lines in a large file.what is command and option i need to use.

View 1 Replies View Related

General :: Deleting File (Oracle Setup) From Root

Dec 18, 2010

I had copied oracle setup in the root. Now want to delete it. I tried the following commands, but couldn't succeed:

rm -R oracle-xe-univ-10.2.0.1-1.0.i386.rpm
rm: cannot remove `oracle-xe-univ-10.2.0.1-1.0.i386.rpm': No such file or directory

While this file there only in file system.

View 2 Replies View Related

General :: Deleting Symbols From File - String Not Found

Aug 4, 2009

I am trying to delete these symbols "[ ]" from a file but it says string not found. I tried: %s/[//g while editing the file not working also tried sed -e '/[/d' and sed '/]/d' still no job.

View 3 Replies View Related

General :: Script For Deleting Matched Line Of File From Another

Sep 3, 2009

I have two text file named 1.txt & 2.txt.

1. txt contains 5 laks of mobile number.
2. txt has 60 laks of mob no.

Situation is that I want to find and delete numbers in 2.txt which already in 1.txt. Any perl or bash script or any other way to get the work done.

I tried the following:
#! /bin/bash
IFS=$'
' for NAME in $(cat one.txt)
do sed -ie "|^$NAME$|d" two.txt done
echo "***DONE***"

It works well with smaller file but it take very very long time even processing 10 thousand numbers.

View 2 Replies View Related

General :: Removing Lines From A File That Are In Another File?

Jan 6, 2011

I have a large text file containing over 180k lines and another text file containing about 1k. I would like to remove lines in the 180k-line file that exist in the 1k-line file.

View 5 Replies View Related

General :: Add Characters To Several Lines In A File?

Apr 17, 2009

I would like to modify the content of a text file in Linux, in the following way:=> the file has several of these lines:./run_pest3 ./g134366.04080_0.062 x 2_d043 1 0.43 results_EC=> I want to modify all lines to be:./run_pest3 ./g134366.04080_0.062 x 2_d043 1 0.43 results_EC0.062i.e., the last number of $2 should be "attached" to the end of $7, for each line.

View 5 Replies View Related

General :: Extract Lines From File Using AWK ?

Aug 5, 2010

I have a file similar to this:

I need to print the last line for each user into a file. The resulting file should look like this:

Is there a way that AWK can match lines from $1 and then print the last line into a file?

View 7 Replies View Related

General :: Adding Lines Of A File Together?

Feb 22, 2010

I'm trying to output two certain fields of a very large text file to 2 very small text files. Then take those files and add all the lines together to come up with a total from each file (two totals).

Here's what I've got:

Code:

#!/bin/bash
echo "0" > /media/in.txt
echo "0" > /media/out.txt

[code]....

Breakdown: Put 0 in a text file to be drawn by respective while loops for math later

Output last 60 integers to a file for total A (new integer every minute)
Output last 60 integers to a file for total B (new integer every minute)

The two while loops are supposed to be adding the lines together. The echo commands at the end are for testing purposes, just to see the output. However, when I run this, I get the output of

Code:

0 0

Which is obviously not what it's supposed to be. Is there a more efficient way to do this or am I missing something in the script that would reset the values to "0"?

View 2 Replies View Related

General :: Delete Last 6 Lines Of File With Sed

Jun 5, 2011

looking to delete the last 6 lines of a file with sed. figured out how to delete the last line..but i want the last six.

View 6 Replies View Related

General :: Add A Line In A File Before The Last Two Lines?

Aug 2, 2010

I need to add a line in a file before the last two lines using a script using standard linux editors like sed but i can't figure it out.

View 2 Replies View Related

General :: View File Ignoring Set Of Lines?

Jun 21, 2010

I'm having a file with repeated particular text lines. So I need to view the file content ignoring these lines. Is there anyway I can achieve this using VI

View 2 Replies View Related

General :: Copy Some Lines In A File And Delete These After?

Jul 20, 2010

I have a file that contains 100 ligns, i need to write a script that read 70 lignes and redirect those 70 ligns to another files and these 70ligns have to be erased in the first file

when i write this command
head -70 somefile.txt>test.txt
or

sed -n 70p somefile.txt>test.txt

i have these 70 lines in the text.txt files
but these 70 lines have to be deleted inthe first file somefile.txt

View 1 Replies View Related

General :: Split A File Into Two - The First Being The First Two Lines And The Second The Rest?

Nov 1, 2010

I'd like to split a file into two, where the first file is the first two lines and the second is the remaining lines (third line to EOF).

View 2 Replies View Related

General :: Delete Lines From File By Their's Length

Apr 27, 2010

i've got a file with sorted words - one on each line.How could it be possible to delete thouse lines that have words of length 1 or 2 (1-2 letters). I guess a good way it will be with AWK, n its fuction length(), but getting it, i dont know how to delete those very lines.

View 14 Replies View Related

General :: Grep And Store Two Lines In Other File

Feb 16, 2011

I have following contents

I want to grep "#2" and want the output as

How to using shell script?

View 6 Replies View Related

General :: Remove All Lines In A File Containing Sameword?

Aug 6, 2010

When i want to remove particular lines containing a specific word in from entire document at a time,i am using the following command.

awk '$columnno !~/specificword/' inputfile > outputfile

But here, coulmn no is my problem, because iam having this in different columns. So i need a solution for it.

How to write such removal command without mentioning column no. , ie irrespective of column no, it has to remove all lines having that specific word.

View 10 Replies View Related

General :: Use AWK To Print Out First Few Lines Of A Text File?

Jul 27, 2011

I have a few rather large text files, and I need a way to look at the first three lines of each. Is there a way to do this using awk?

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved