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


ADVERTISEMENT

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 :: 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 :: Sed Regex To Match Words Via A Pattern

Oct 24, 2010

I have some lines of text and I want to detect words that meet some criteria with sed.

E.g. The line "tetris cat dog test cactus stereotype"

I want to detect the word that contains two (2) ore more t letters. That mean the words tetris, test and stereotype.

The following regex doesn't do the job because it can;t distinguish words very well.

I thinks I have ti incorporate something like [^ ] in the regex but I wasn't successful...

View 3 Replies View Related

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 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 Grep To Match Multiple Lines?

Feb 3, 2011

I have done this before but i cant really recall now

I have a text file and i want to grep the word "interface" and 10 lines following it. I think there was some switch like grep -A or something ?

View 2 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 :: Use Of Uninitialized Value In Pattern Match - Perl

Jun 26, 2011

I want to strip the process name from the hosts - i did it with the code below.

I have two questions - is there a more compact way to strip off the process names? usalso i want to get rid of the errors after extracting the hostname. It is complaing about $arry[1]. using my $arry[1] is not allowed. Assigning the slice to a value, as is 'my $sliced_arry = $arry[1]; print $sliced_arry , does not work either.

Code:

Use of uninitialized value in pattern match (m//) at newcomm_stats.pl3 line 7, <NEWCOMM> line 16 here i get what i want - just the host name, but still get those nasty errors. assigning a value to $1 does not work, and localizing $1 with 'my' is not allowed.

Code:

View 4 Replies View Related

Slackware :: No Packages Match The Pattern For Install?

Aug 10, 2010

seemed to have buggered up installing netbeans on my slackware 13.0 machine. I got the source (the zip file), which i copied into the extracted slackbuild, then did a

Code:
./netbeans.SlackBuild

It all seemed to work fine, at the end it told me my package could be found in /tmp. So i went there and did a

Code: root@slackLap:/tmp# slackpkg install netbeans-6.8-i586-1_SBo.tgz

Looking for netbeans-6.8-i586-1_SBo.tgz in package list. Please wait... DONE

No packages match the pattern for install. Try: /usr/sbin/slackpkg reinstall|upgrade

ps i'm running 32bit slackware 13.0

View 3 Replies View Related

Programming :: File Renaming Based On A Pattern Match

Jan 8, 2011

What I am attempting to do is rename some television shows into the format that my PVR will understand for the naming convention. I have a script that cleans them up about 95%, now I just cant figure out the last little detail..

For example: NCIS_01.mkv
I think it can be done in sed, but I just figure out how. I need it to be renamed to: NCIS_s01e01.mkv

How can I make sed (or something else) match the last "_" and any numbers after it until the period and then insert text between them reliably?

Depending on the show, it can be something like: This_show_name_243.avi so I need it to be more flexible than I can figure out how to do..

View 6 Replies View Related

General :: Bash - Search For A Text Pattern?

Nov 28, 2010

I need to search for a string "teststring" in all *.java files coming under /home/user1/ (including subfolders). How can I do it in linux via shell command.

View 5 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

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

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

General :: Check If Any Of The Parameters To A Bash Script Match A String?

Sep 8, 2010

I'm trying to write a script where I want to check if any of the parameters passed to a bash script match a string. The way I have it setup right now is if [ "$3" != "-disCopperBld" -a "$4" != "-disCopperBld" -a "$5" != "-disCopperBld" -a "$6" != "-disCopperBld"]but there might be a large number of parameters, so I was wondering if there is a better way to do this?EDIT:I tried this chunk of code out, and called the script with the option, -disableVenusBld, but it still prints out "Starting build". Am I doing something wrong?

while [ $# -ne 0 ]
do
arg="$1"

[code]....

View 3 Replies View Related

Programming :: Delete Lines Between Match?

May 15, 2011

My problem is like this I have to delete all lines between two pattern match example- suppose below is the content of the file then i have to delete all lines between text1 and text2

...
text1
abc
def
ghi

[Code]....

View 14 Replies View Related

Programming :: Sed Match Last X Lines Of A File

Mar 17, 2009

I'm trying to find the correct sed syntax to match from a given pattern to the end of the file and then append that pattern to the end of the file.

I was trying:

But that prints each line right after its original occurrence. I want to match the block and then append it to the end of the file.

View 12 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

Programming :: Display All Lines Before A Match Is Found?

Sep 9, 2010

I have a file, and I have to display all the lines from the beginning of the file till a matching string is found.

I know grep with "-a", "-b" as option does exist, but it needs the number of lines to be printed in advance. eg grep -b 10 "search_string" file so it will print 10 lines before a match is found.

View 3 Replies View Related

Programming :: Sed - Awk - Perl - Merge Lines Unless They Match A Certain String

Apr 15, 2011

What is the best way to merge lines, in sed, awk or perl, that occur between certain strings? I'm new to sed scripting and I have been working on this for some time now. I have a large file (sample below) that I need to edit.

What I need looks something like this.

I'm working with a very large file so simply merging all the lines then adding a new line character before ">contig" and after "translated" won't work, at least not with sed.

View 5 Replies View Related

Programming :: Sed - Match One Line Make A Substitution A Few Lines Down?

Jun 6, 2011

I need a substitution of a particular string (StringA) with another string (StringB). However, there may be more than one occurrence of StringA within the file, but only one instance needs to be changed, which is why I'm trying to be sure of it's positioning against something I know will be unique in the file, and will always have the same distance from the string to be replaced. So, I intend to match on a string (StringC) above the string to be substituted and then have sed go to StringA below and replace with StringB.

So far, I have had some success with the following:

Code:

... but I can't help thinking that there *has* to be a cleaner way of doing it.

View 6 Replies View Related

Programming :: Unable To Match Across Multiple Lines In Perl

May 11, 2011

I'm trying to split a text file into various parts. Everything in between "123" and "break" (including linebreaks) goes into the splitted file.

e.g. using this text file:

This should split into 4 files. However I'm only getting 2 files: one for the line "123break" and one for "123 blah break". The two occurrences that contain linebreaks are being ignored. The .* part of my match should capture linebreaks seeing that I'm using the /s modifier shouldn't it? Even when I use the match /(123 break)/gs it still doesn't capture the first occurrence. I'm using Perl v5.12.3 (from ActiveState) on Windows XP. The text file is also in Windows format.

Code listed below.

The above code generates two files Output_1.txt and Output_2.txt which contain "123break" and "123 blah break" respectively. I want it to generate four files.

View 4 Replies View Related

Programming :: Regular Expression To Match Lines In A File That Do Not Start With # Or A Blank Space?

Dec 25, 2010

i have a file like this

# comments
#comments
#comments
bla bla

[code]....

i want to grep lines which do not start with # or a blank space. like

bla bla
bla bla

how do i do this? i tried grep --invert-match '^#' which gives lines not starting with # but gives me blank lines too i tried grep --invert-match '^#|^ ' which will give lines not starting with # OR not starting with blank ( which means any line including ones starting with #

View 3 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 :: 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







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