General :: Find Pattern And Comment Out 2 Lines After It?

Oct 14, 2010

How do yo find a pattern with sed or awk and then:

- add a # at the beginning of the line containing it

- and add a # at the beginning of the following 2 lines, too?

Say, I want to comment out the line containing "which 0launch" and the two lines following it:

if [ -x "`which 0launch`" ]; then
exec 0launch http://rox.sourceforge.net/2005/interfaces/ROX-Filer -S
fi

Expected result:

#if [ -x "`which 0launch`" ]; then
# exec 0launch http://rox.sourceforge.net/2005/interfaces/ROX-Filer -S
#fi

I need this because I do not want to comment out every line containing "fi", just the "fi" of this specific if statement.

View 3 Replies


ADVERTISEMENT

Programming :: Find Pattern That Extends Over Several Lines?

Jun 12, 2011

Is there a convenient method to find a text pattern that extends over several lines? In this case:

Empty line
LineConsistingOfSingleWord

Preferably to return the line number where the pattern occurs to determine the first such after a known line number. In other words, in order to extract a block of text from within a file.

View 3 Replies View Related

Programming :: Sed: Find Pattern And Delete 5 Lines After It?

Mar 23, 2010

I am trying to edit a print file.

For every occurence of the ^L form feed character I need to remove 5 blank lines after it but still keep the ^L.

I am a rare user of sed and am ok with the basics but am struggling with this.

View 4 Replies View Related

General :: Get Rid Of Surplus Comment Lines With Sed?

Feb 14, 2011

I have a large text file and I have some comment lines in it beginning with $.

Now here is the challenge there are some lines where there is actually a written comment after $ (with some blanks between)

Then there are lines with only $ on it - with maybe some trailing spaces.

I would like to delete these dummy lines...

Lets say from

$ This is valid comment
$
$
$

[Code]....

View 3 Replies View Related

General :: Find Pattern After Specific Pattern

Oct 11, 2010

I want to go through a log file and find pattern1 and then a pattern2 only after pattern 1.So for example I want to know howManyRecords was in 13:30.I figured I grep for "start time for the job" and then only after that (and before the next occurence of that) grep for "howManyRecords". Is this a sane way?

View 1 Replies View Related

General :: Use Sed To Delete All Lines Before First Match Of A Pattern?

Apr 14, 2010

I have to use sed with this problem, and sed is extremely complicated, they could probably teach a whole class on this entire function.

Here's an example to show what I need to do:

Code...

how would I say that every line before I reach the first match of "sweet" should be deleted so that the output will look like: Code...

View 9 Replies View Related

General :: Search For A Pattern Between Lines 1500 To 2500?

Jan 25, 2011

I have 8 files, and each contains around 2000 lines. I want to search the particular word in these files between line number 1500 to 2500.

The output should look like:

sample_1.txt :
1510:declare var testing
sample_2.txt :
1610:declare var testing
sample_7.txt :
1610:declare var testing
sample_10.txt :
1710:declare var testing

Is it possible to use grep for this task?

View 4 Replies View Related

General :: Use Sed In Bash To Match Pattern Contained In 2 Lines?

Mar 14, 2011

I have a file called test. It has the following contents.Code:there youI want the output to be.Code:replaced youI am trying to use the sed command to replace every occurance of "hey newline there" with "replaced". I tried the following naive apporach.Code:sed 's/heythere/replace/' testThis gives a result containing the same data as the test file.

View 3 Replies View Related

General :: Sed - Append Four Commas ',,,,' At The End Of Lines Containing The Pattern 'Response' In A Text File

Nov 5, 2010

Using sed, I am trying to append four commas ',,,,' at the end of lines containing the pattern 'Response' in a text file with lines such as these:

6,Pulse,50,254968,14886,NA,,,,
7,Picture,8,265157,0,1,15045,2,0,15000
7,Response,1,271553,6396,1
7,Pulse,50,274969,9812,NA,,,,
8,Picture,1,290232,0,1,15045,2,0,15000
8,Pulse,50,294969,4737,NA,,,,
[Code].....

View 1 Replies View Related

General :: Copy Lines Starting And Ending With Specific Pattern From Multiple Files To A File?

Jul 27, 2011

A function by name abc is called in many files. I want to copy all the lines with the function call to an output file.A simple grep on function name doesn't help me as the function call is spanning across multiple lines as follows:

abc(parameter1,
parameter2,
parameter3);

So I want to copy all the three lines (till semicolon) to the output file.The problem is because there are more than 200 calls for the same function and I cannot do it manually

View 2 Replies View Related

Programming :: How To Grep Pattern Which Is Split In 2 Lines?

Dec 9, 2010

I need to grep a pattern which can be present in one line or could be split in 2 lines.Normal grep wont work in this case. Can anyone please help on this?There are 100's of files in which i need to search for this pattern so time is also a constrain.

View 5 Replies View Related

General :: Where To Find Rhce Dumps Of New Pattern

Aug 27, 2010

wher i wil find rhce dumps of new pattern.

View 3 Replies View Related

Programming :: Replacing Lines With Pattern Partialy By Different File?

Apr 12, 2010

I have two files, where the 1. file has special lines that need to be updated by lines from a 2. file:file1:

foo
foo
foo 0.00 0.00 0.00 pattern

[code]....

View 1 Replies View Related

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 :: Replace Pattern In Specific Lines And Column With AWK?

Apr 24, 2010

Im tryng to replace in specific column and line number within a file where its 3erd column contain the same string in all lines.

[code]....

My goal is to replace only first and last ocurrences of "Normal player", with the following desired output:

[code]....

Im not sure how to use the "IF" and "AND" conditions together. I�ve tryed with the code below, but the script replaces the string for every line.

[code]....

how to replace values for specific column in first and last lines within same AWK script, without taking reference data in other columns?

View 10 Replies View Related

Programming :: Search File By Pattern And Then Delete Corresponding Lines In Shell?

Sep 16, 2010

I have such a file(test.txt):

abc 123 456
abc 256 145
axd 125 225

[code]...

View 8 Replies View Related

General :: Add (not Replacing) A Pattern Match With A Similar Pattern?

Aug 30, 2009

I'm writing a bash script to search html files, and when I find any occurrence of an img src tag like this:

<img src="123-picture-normal.jpg" alt="some random user entered text" border="0">

I want to add a second line below it that looks like:
<img src="123-picture-thumbnail.jpg" alt="some random user entered text" border="0">

All I need to do is duplicate the line but replace "normal" with "thumbnail"

Each file can have multiple img src tags with different numbered jpgs.

I have a feeling this is a job for sed, but I'm struggling with it. Any ideas?

View 2 Replies View Related

General :: How To Use Find With Two Lines Together

Jan 19, 2010

I am trying to search for

Code:
<cats>
Sports
</cats>

how do i use the find command to search for <cats>Sports The problem here is that the word Sports is in the next line of <cats> so I cant use -

Code:
find /test/upload/ -type f -name "*.xml" -exec grep -l "<cats>Sports" {} ; -print
How do I put the next line string?

View 8 Replies View Related

General :: Bash Script To Find Lines Containing Two Different Strings

Mar 13, 2011

I'm trying to write a bash script to find all lines containing two different strings in many files. I don't have access to egrep so I want to use sed for this purpose.

The files will look like this:
FileX
------
Info:18
Data:76
Contact:me@home.com
Start:1500

I want to generate a new file from these files with only the rows containing Data and Start. Something like this:
for y in `ls /file*.db`;
do sed '/Data|Start/p' $y > newfile
done

View 7 Replies View Related

General :: Filtering Out Duplicate Lines From A Find/grep Output

Mar 22, 2010

I have some big files of logs that contain errors printed by an app. They are most of the time relevant, however most of them are similar. So i figured i could check what happened between a time interval with a find.

Im using this one

Code:

And I get an output similar to this one.

Code:

Is there a way to condensate the output lines to get only one or two, indicating the start and last occurrence of a block? Or I need to create a program to do so?

Because right now I get thousands of similar lines, but when I'm scrolling through them i sometimes miss relevant information that i would've otherwise noted if it wasn't all that spammy.

View 10 Replies View Related

General :: Find File With Dir/file Pattern?

Jul 26, 2011

i'm just curious if i can search for the dir/file pattern in the single "find" command?
here is an example:

dir1/dir2/dir3/file.txt
dirXX/dirYY/dir2/dir3/file.txt
dir1/dir4/dir3/file.txt

i want to search for the pattern "dir2/dir3/file.txt"

View 12 Replies View Related

Programming :: Use Sed To Find String Pattern And Delete Subsequent Characters?

May 3, 2010

I have a file with a number of strings like the ones below

string1#m1asdfe23easdf23wefas
string2#mfaaeb2vr1rhserh
anotherstring#ji89ensrsegr
anotherone#m1ynmdt324nsdt

I'm trying to delete everything after #** so that

string1#maasdfeaveasdfawefas
string2#mfaaebvrserhserh
becomes
string1#ma
string2#mf

tried sed 's/#..*//g' but as you all will know it returns string1, string2 etc.

View 12 Replies View Related

Programming :: Search A File For A Particular Pattern And If Pattern Found Replace The Line With New Text?

Feb 24, 2010

I want to search a file for a particular pattern and if pattern found replace the line with new text. i am using awk 'match($0,"pattern") != 0 {print $0} ' filename to check if the pattern exists.how do i get the line number of the pattern and delete that line and replace the line with my new text?

View 1 Replies View Related

Programming :: If Statement Pattern Search / End Of Pattern Special Character?

Apr 29, 2010

I have to enhance the behaviour of a backup script written in perl. I don't need to change it, what I need to do is to create a bash script that does some checks like file name and file size, execute the backup script then check if the backup files match the original files.Here's how I try to do it:

- read the files from the original files folder
- store them in an array
- search in the array the files that have a specific file extension
- store the file names that match the search pattern (I know the backup script skips some files so I can hardcode the search pattern)
- run the backup script
- read the files from the backup folder
- store them in an array
- compare the original files name and size stored in an array with those from the backup folder
- send a report email

View 3 Replies View Related

General :: Comment On Partitioning Strategy?

Mar 7, 2011

I'm planning to partition a new hard drive to dual-boot Mint+Mepis. I've read partitioning tutorials and posts, and want to check my understanding--I'd appreciate input from an experienced person.For 500GB hard drive, dual-boot Mint+Mepis:

--Mint: / root partition for OS; /home partition for ease of upgrading
--Mepis: same as Mint
= four partitions

And:
/swap partition to be shared between Mint+Mepis
/shared partition for shared data
= two partitions

Total = six partitions

Since four primary partitions are allowed, I should use three primary partitions and one extended partition containing three logical partitions.Is that correct?If so, what should go where? I assume there's an optimal strategy--Should each /root of Mint+Mepis go in a primary? What should go in the other primary, and in the three logicals? Or maybe I don't need three primaries?--use two primaries and four logicals?

View 4 Replies View Related

General :: Delete All Lines Containing A String, Plus 4 Lines Below It?

Jan 26, 2010

I've come across an unusual requirement for a service in my Ubuntu system.Simply put, I need to find a way to search for all instances of a term in a file, delete lines containing containing that term, and delete four lines below each instance of that term. ither that, or copy the entirety of a file to a new file and skip over all lines containing the term plus four below it.This sounds kinda weird, I know. Without going too far into detail, I either have to change the logfile format for a server I'm running which is a huge pain in the butt, or I can just run a script to edit an HTML report generated from said logs. (Said report is really just for managers to peruse, and I like my log format, so I'm pursuing option 2.)

View 4 Replies View Related

Software :: Replace Newline Pattern In File By Other Newline Pattern In A Shell Script?

Nov 22, 2010

I have several (vhdl) files containing a pattern with newline characters that I need to replace by another pattern that also contains newline characters.

I start with something like:

Code:

I want to replace it by something like:

Code:

(I need to paste some lines)

As I need to do this (very) often I want to use a shell script.

I tried:

1.

Code:

result:

Code:

2.

Code:

result:

File remains unchanged

3.

Code:

result:

Code:

4.

Code:

result:

Displays the unchanged testfile

How I can automate the pattern replacement?

Code:

View 9 Replies View Related

Ubuntu :: Find Word Print Out # Of Lines

Feb 17, 2010

this is driving me crazy. How can i in the terminal, display only the first 5 lines of say dmesg

View 7 Replies View Related

Ubuntu :: Using Sed Or Awk To Find And Delete Lines In A File?

Dec 21, 2010

I have a bunch of text files, all of them have a .txt extension. They are all located in subfolders of the /MyTextFiles folder (but could be anywhere, no idea what depth). If any line in any of the text files has the word "hello" I want to delete that entire line. I know sed and awk are made for this problem but I can't seem to get the syntax correct.

View 1 Replies View Related

Server :: Find A String In A File And Delete That Line As Well As X Lines After?

Jun 24, 2010

I need to find a string in a file ... then delete the line it is on, as well as the next 6 lines. Or, delete the line the string is on and all subsequent lines until the search finds the character "["

example:

filename = test.txt

contents:
[foo]
test>test
test>test
test>test

[Code]....

so, in this example. I'd like to search the file for string 'foo' and delete all lines from that line until [bar] (not deleting the line with [bar])

View 3 Replies View Related







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