Programming :: Sed -n '/pattern/{n;p;}' Is Missing Matches In File?

Jun 16, 2011

I have an interesting problem, sed '/pattern/{n;p;}' file, doesn't seem to be catching all of the matches in my file. As an example of this see below.test:

Turn
Turn
Turn

[code]....

View 5 Replies


ADVERTISEMENT

Debian :: Append File Content In Another File When Pattern Matches

Feb 5, 2010

I have a file, say abc.txt, whit some text lines.The I have a second file, say 123.txt where at a certain point one can read "WORD".I would like to append the whole content of abc.txt (as it appears in abc.txt) in the line after "WORD".

View 1 Replies View Related

Programming :: Shell Script To Delete Part Text Of A Line If Pattern Matches?

Apr 12, 2010

I am trying to create a shell script, on taking a input file as parameter, which need to do 3 things

1) create a copy of existing file.

2) add a new line to the copied file.

3) strip off all the absolute paths inside the copied file

The first 2 points are straight forward. but i am finding it difficult to acheive the 3rd point. myself not very good with awk and sed. but gave it a shot in vain. For example, the input script consists of below,

PROGRAM=`/usr/bin/basename $0`
HOST=`/usr/bin/uname -n`
echo Start $PROGRAM `/usr/bin/date` |
/usr/bin/tee -a $LOG

The output of the script should look like,

PROGRAM=`basename $0`
HOST=`uname -n`
echo Start $PROGRAM `date` |
tee -a $LOG

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

Ubuntu :: Egrep Command To Return Matches For A Group Rather Than The Whole Pattern Itself?

Jan 17, 2011

To put it simply I want the egrep command to return matches for a group rather than the whole pattern itself.For example:

Code:
egrep "reals([0-9]+?m[0-9]+?.[0-9]{3}s)" tmp
returns
"real 0m1.001s"

But I want it to return just "0m1.001s", the portion is the group. I can just apply egrep to whatever the first command returns but is there an easier way to do it?

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

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

Programming :: Searching Pattern In Tab Delimited File Using Grep

Mar 4, 2010

Suppose i have a file(1.txt) separated by TAB delimiter in a line

1 B AB 2
2 C AB 2

if I need to search for the records having B?? using grep.If i need to perform multiple search like line having "C and AB" or "B and AB"??

View 5 Replies View Related

Programming :: Sed To Read The File And Replace And Insert The Pattern?

Jun 11, 2009

I want to read from the file and check for the pattern, if the line has some word like <string>: then string should be copied into buffer. Afterwards, I want to insert the same <string> with some word in the next line of the file. use sed command to perform the above mentioned operations?

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

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

Debian Programming :: Check If Login Password Matches What Have Specified

Feb 26, 2014

I'm trying to create a program that will go through a list (one word at each line) from the file pwdlst.txt and try to log-in with the passwords entered in the file. When the program tries with a password that matches the current one, the program will stop and print out "The password is: %s" % password. This is what I created so far:

Code: Select allimport urllib
import urllib2
import cookielib

[code]...

get the error and print when the log-in attempt is deniedgo through the list (pwdlst.txt) and try each password one at a timestop the program when the password matches

View 2 Replies View Related

Programming :: Regular Expression To Match URL Matches Fragments - Python?

Aug 26, 2010

I have made this:

Code:

from urllib import urlopen import re

current_site = urlopen("http://www.krak.dk/").read()
search = re.findall("((http://|https://|ftp://)|(www.))+(([a-zA-Z0-9.-]+.[a-zA-Z]{2,4})|([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}))(/[a-zA-Z0-9%:/-_?.'~]*)?", current_site)

[code]....

I only want to match complete URL's. how do i avoid matching the fragments ?

View 4 Replies View Related

Programming :: Write Regexp That Matches String That Begins With Whitespace Or Contains Newline?

Dec 10, 2010

How do I write a regexp that matches a string that begins with whitespace or contains a newline, but not necessarily both?

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

Programming :: Add Texts Using Sed In Matching Pattern?

Feb 3, 2011

I need to add some text using sed before and after the matching pattern. Does any one have any clue?e.g.cat /my/file | sed -e "s/first pattern/New Pattern/g" . /my/file.bakNow I need a result like New Pattern

View 7 Replies View Related

Programming :: Delete Line Containing A Pattern?

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

Programming :: Split A Pattern In Perl?

May 17, 2010

I am trying to split a pattern in perl and so far I cannot get it to work. I have a pattern that looks like this:

76|2455311|2455312|00:00:00|00:00:00|Once|0|Donkey | |

I always need to print out the 8th field. So in this case donkey. Here is what I have so far:

Code:
#!/usr/bin/perl
use strict;
use warnings;

[Code].....

View 6 Replies View Related

Programming :: Setting IFS To Ignore Pattern?

Mar 11, 2010

I'm working on a backup script which takes the following input:

Code:
RevBackup.sh <options> <source> <target>

The problem I'm having is that the source and target might contain spaces in the path. ie. /home/eRJe/My Documents

I would like the script to ignore " " (backslash-space) as being a delimiter. how could I do this without stopping a normal space from being a delimiter?

I could do this with IFS. But so far I have only found info about setting a delimiter and not to "ignore" one

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

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

Programming :: Gawk - Using Variable In Search Pattern?

Apr 4, 2010

yes, this is a homework question, but no - I'm not trying to get anyone to do it for me. I think that I am really close, but can't quite get one small aspect to work. in gawk, I want to include a variable name in the search string, but the below code doesn't work.

read -p 'Login name please? ' uLogName
userID=$(gawk -F: '/"$uLogName"/{print $3}' /etc/passwd)
echo $userID

[code]...

View 3 Replies View Related

Programming :: Pattern Detection In The Logs + Notification?

Sep 6, 2010

I'm looking for a solution of pattern detection in the logs and then allows to send me an email notification if it detects the previously specified term.I use already Logwatch, but I do not know if it is possible to configure it for that use.

View 1 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 :: Awk Command - Search Pattern To Look For Last Occurrence

May 11, 2011

Any solution using awk/sed/regexp or other standard linux utility (this is for a mix of RH versions)? I am dealing with some very large application log files. I want to see everything that has been written to the log since the last application restart.

For an example take a log file like this:
Code:
# cat test.log
1 msg
2 msg
3 restart 1
4 msg
5 restart 2
6 msg

The following command is close to what I want:
Code:
# awk '/restart/,G' test.log
3 restart 1
4 msg
5 restart 2
6 msg

But the awk command grabs the first restart not the last. If it was working the way I wanted I would see something like this:
Code:
# awk '/restart/,G' test.log
5 restart 2
6 msg

So, I need something in that search pattern that says look for the last occurrence. I know how to do this with a pipe line - I could reverse the file and then do a similar awk and reverse back, or I could find the number associated with the last restart and then use that in the awk search. But these just take too long because the file is too big.

View 14 Replies View Related

Programming :: Changing Pattern From String In Perl

Jun 3, 2011

I am new to perl and not able to understand all the pattern matching.

I using this script to send the status to another Nagios server using ncsa. Nsca don't transmit "()" So I need to remove them before sending.

Currently I am using

Code:

for the string

Quote:

This is working fine but its is not working when there is change inside the bracket for e.g (6290)

I want to change this code to work for any change with in the brackets.

View 14 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 :: Grep Until Certain Character Or Pattern Appears

Jun 25, 2010

I have the following command that greps "/etc/cron.allow" and displays the following 9 lines of $file grep -A 9 "/etc/cron.allow" $file On the other hand I would like to grep a file for a certain text display the next couple of lines and stop when i hit a specified word or blank or pattern.Basically I would like my grep to end when the shell hits a blank, certain key word or pattern specified in command.

View 7 Replies View Related







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