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


ADVERTISEMENT

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 :: Java Regex - Use Regular Expressions Find Out What The First Two Characters Of The String Are

Feb 2, 2011

What I am doing is reading the text from a text document and storing all of the text inside of a ArrayList. I then set one of the values of the Arraylist as a string. I want to use regular expressions find out what the first two characters of the String are. if first two characters = "//" then function(); I only care about the first two characters though. If you need any more information, just ask.

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

General :: Find A Substring In A String And Get The Next 3 Characters

Mar 5, 2010

for example

010100
this is the string

the substring is 010

i need to search for this substring and i also need to return the next 3 characters i.e 100.

i need to apply this for this string

01010000001001100000100010

View 8 Replies View Related

Programming :: Check If A String Entered By User Starts With A Particular Pattern Or Not?

Feb 4, 2010

How do i check if a string entered by a user starts with a particular pattern or not?

View 3 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 :: Sed: Delete Last Line Matching A Pattern?

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

Programming :: Split A String By Every Nth Characters?

Jan 17, 2011

splitting a string by every nth characters. I'm using Python 2.7.1 because I'm using older libraries, if that matters.

For example, if this is my input:

Quote:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac elit nibh, vitae venenatis ligula. Vestibulum a varius turpis.

Splitting it by every 10th character should produce this list:

Quote:

[ "Lorem ipsu", "m dolor si", "t amet, co", "nsectetur ", "adipiscing", " elit. Sed", " ac elit n", "ibh, vitae", " venenatis", " ligula. V", "estibulum ", "a varius t", "urpis." ]

View 6 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 :: How To Insert Characters Into String In Shellscripts

Nov 15, 2010

My problem is to insert one sign like space or ':' into a line or string.The goal is to get a demiliter for `cut`.I tried to do it with `tr A-Z "'A '-'Z '" and such but without success.I guess a while read loop could do it but I don't know howto use it with ` expr length $STR`

View 5 Replies View Related

Programming :: Remove Special Characters From String

Jan 30, 2011

I am reading strings from a file using readline() function,the file contains some strings which has only special characters, I need to avoid the strings which has only special characters, the special characters are not similar. How to do it in python.??

View 2 Replies View Related

Programming :: Count The Number Of Occurrence Characters In A String ?

Jan 26, 2011

How do I count the number of occurrence characters in a string in an efficeint way ?

How do I reverse the words in a string with out using temp variables if possible . (if not possible use temp variables ?

Why do I specify dependedcies for header files in the Makefile ?

View 2 Replies View Related

Programming :: Remove All Alphabetic Characters At Beginning Of String

Jul 26, 2010

I am working with a Tcl script and have some strings in the following format (RE):
[a-zA-Z]+[0-9]{6}-[0-9]

There are some leading letters, combinations of capital and lowercase. Then six digits, followed by a hyphen, then one more digit. I would like to remove all of the leading alphabetic characters from the string. The resulting string would then be in this format: [0-9]{6}-[0-9]. In other words, six numeric digits, a hyphen, then one more digit.

I have tried:
Code:
set newstr [string trimleft $origstr alpha]
But that only removes the first alphabetic character, not all of them.

I couldn't get anything with regsub to work correctly, but I am somewhat of a noob with RE's in general and regsub in particular. There are usually 5 leading letters at the beginning of these strings, and I could in most cases get away with using string replace and constant indices to extract the substring. However, my preference is for this to be robust enough to handle all cases with 1 through n leading alphabetic characters.

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

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

Software :: Find And Delete String In Text Files?

Mar 6, 2010

I have a series of file names in a text file that I generated by running
Code:

bash-4.1# ls -alt *.txz | awk '{print $8}'
and then copy pasting the output. All of these file names have the version number
Quote:
-4.4.1-x86_64-1alien.txz

I just want a method to remove that version number from all the filenames so that I can then add all the packages without version numbers to a blacklist file.

I've tried kwrite and mousepad and both have a search feature and a replace feature but I haven't been able to just have the text removed successfully.

View 3 Replies View Related

General :: Extract A String Within A String Using A Pattern?

Nov 4, 2010

i have a file name using the following pattern:

PREFIX: AR
SOURCE: LEGACY
DATETIME: YYYYMMDD_HH24MISS
SUFFIX: .txt

sample filename:AR_LEGACY_20101104_105500.txti want to extract the source which is LEGACY in this case. how do i do this using shell?

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

Programming :: Delete Parentheses In A String?

Jul 1, 2010

I have the following string 1524)), I want to get rid of the parentheses. I have tried SED and AWK without success.
The last I tried was: echo "1526))" | sed 's/)).*$//'

View 4 Replies View Related

Programming :: Need To Delete A Specific String

Aug 27, 2010

These must a be a question you received a lot, but I couldn't find a similar thread! It's a simple question.
I need to delete a specific string from a file. For example the specific numbers "3456" from a file. I've tried with the tr comand, using
Code:
tr -d '3456' file,
but it also deleted whichever ocurrence of 3,4,5,6 from my file. Should I use a regular expression?

View 7 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 :: Delete Line In File Matching String?

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

Ubuntu :: Delete All ASCII Characters In File - Leave Chinese Characters Only

Jul 8, 2011

What command could I use in terminal to delete all ASCII characters? That is, delete a-z, A-Z, 0-9, and all punctuation? I have a file containing Chinese characters, and I want to remove everything else and leave just the Chinese.

I can use grep to leave only the lines that have Chinese in them, but this still leaves a lot of non-Chinese stuff on those lines. Does anyone know how I could actually remove everything that isn't Chinese?

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

Programming :: Copy String A To String B And Change String B With Toupper() And Count The Chars?

Oct 22, 2010

copy string a to string b and change string b with toupper() and count the chars

View 3 Replies View Related

Programming :: Find A String In A File Without Using Grep?

Oct 27, 2010

I want to write some code to search for a specific string in a text file, but without using grep command.

View 5 Replies View Related

Programming :: Et A Code In C++ To Find The Md5 Checksum Of A String?

Jul 16, 2010

get a code in c++ to find the md5 checksum of a string.

View 3 Replies View Related







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