Programming :: Using Sed Replace Line Containing Particular String By A Single String?

Oct 16, 2010

I have a set of lines as ahown below:

Leon went to school
Leon came back from school..
Leon had dinner...

I have to replace the line containing "dinner" by a single string LUNCH...

View 2 Replies


ADVERTISEMENT

Programming :: Pthread - Take String From The Command Line And Creates A Thread To Print The String

May 3, 2011

I've been trying to understand pthread in C a little better. So I made a simple program that takes in a string from the command line and creates a thread to print the string. I've looked online and copied the basic concepts but there are something things I'm confused about. The programs works just fine, but I have questions. Here's what I have so far.

[Code]....

One thing I'd like to know is why the 3rd argument in the pthread_create function which is my SendMessage function needs to be typecasted to a void pointer and then send the address of the function. Also as for the 4th argument, I would see typecasting to void pointer in some of the pthread examples I saw online, but in my case I'm passing a char pointer, would this be correct? In which case would I ever want to pass a void pointer?

Do I need a pthread_exit(NULL) in my main and in the SendMessage function? If so, why? I added the sleep() function so that I could let the pthread_exit function in my SendMessage function execute first. I simply saw that the online examples on pthread had pthread_exit() in both locations.

View 6 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 :: Replace An "entire" Line Containing A Particular String With A New Line?

Mar 12, 2010

I think this can be done using sed. Let's say I have file called, "orig.txt" with following contents:

Code:
[User Prefs]
Ignore Unrequested Popups=1
DevTools Splitter Position=500
History View Style=0

[Code]....

So basically if a line contains the word "Home URL" then go ahead and replace that *entire* line with the supplied *new* line.

View 4 Replies View Related

Software :: Replace A Text String In A File With A Random String - With Sed ?

Sep 2, 2010

I have a line in a text file that has 40 random characters within a tag and i want to change the characters to a new set of 40 random characters (alphanumeric a-z 0-9 etc)

The line in the text file looks like this:

Quote:

How would i go about doing that?

Also second question same as the above but how would i remove them instead of replacing them?

View 14 Replies View Related

Fedora :: Replace A String By A String In Text File?

Apr 26, 2011

If I have a word in a text file and I need to replace it by another word (for example, i need to replace abc by fff) so what is the command I can type it?

I am using vi editor.

View 3 Replies View Related

General :: Replace String With Empty String Of Dir Path ?

Apr 2, 2011

I want to replace a string of directory path in a string to empty:

Code:

But this doesnt seem to give me the desired thing:

Code:

This gives the desired outcome, but its specific, i need a variable in the sed not a string. And if I replace STRING="/mnt/sda1/record/$dd/" then I cant use it for something else, cause its has all the weird backslashes now.

View 3 Replies View Related

Ubuntu :: Replace A Line Containing Particular String Using Sed?

Oct 16, 2010

How to replace a line containing some word by only another word...

Ex: The sed program is the Linux stream editor utility The pattern is a regular expression that you wish to match and replacement is the new string to ..

replace the line containing 'program' by only word LINUX

View 1 Replies View Related

General :: Replace Nth Occurence Of String In Each Line Of A Text File?

May 20, 2010

I have large text files with space delimited strings (2-5). The strings can contain "'" or "-". I'd like to replace say the second space with a pipe. What's the best way to go?
Using sed I was thinking of this:

sed -r 's/(^[a-z'-]+ [a-z'-]+) /1|/' filename.txt

View 2 Replies View Related

General :: Perl Command To Replace String By Line Numbe?

Jul 10, 2010

I want to know the Perl command to replace a string by pointing the line number. I know how to replace a string without pointing a line number but I am in need to replace only the two matching string in a file

View 6 Replies View Related

General :: Awk Gsub() Command - String (column) Manipulation - Replace The Value Of The $1 Column In The Awk Print String?

Mar 7, 2010

i use this script to get the time and date of back and fourth transactions for a particular execution id. I use a substr command on the 5th column to to cut the milli seconds off the time value. - otherwise the times would look like 08:30:04.235

grep <executionID> <auditfile> | awk '{ print $1, $2, $3, $4, substr($5,1,8}
FIX -> Mon 3/1/2010 08:30:04
FIX <- Mon 3/1/2010 08:32:36
FIX <- Mon 3/1/2010 08:35:08

[code].....

anyhow - i append two sed commands to further clarify the direction of the message.

awk '{ print $1, $2, $3, $4, substr($5,1,8} | sed -e 's/->/ ->IN/g' | sed -e 's/<-/<-OUT/g'
FIX -> IN Mon 3/1/2010 08:30:04
FIX <- OUT Mon 3/1/2010 08:32:36

[code]....

I tried using an awk gsub () command within the string instead of the two seds, but it did not work:

awk '{ print gsub(/<regex>/, <replace with>,$1), $2, $3, $4, substr($5,1,8}

the sed works ok, but it would be cooler to make the replacement within the awk command:

gsub(/->/,-> IN, $1)

Is there a way where i could replace the value of the $1 column in the awk print string?

View 1 Replies View Related

Programming :: Replace The Last Character String?

Jan 19, 2011

how to replace last character string. For example

$>export T1=abcde
$>export T2=xyz

how to get result abcdxyz?

View 10 Replies View Related

Programming :: Replace A String Within A File ?

Feb 28, 2009

I've found some scripts that replaces a string in a file but it's not quite working for me.

And I'm trying to replace a tag in an xml file that looks like this

So I ran a command line like this perl -w -i -p -e "s/xmlns="'http://mydomain.org/replacethese.xsd'">/>/g" testfile.xml

And I get a error output

Search pattern not terminated at -e line 1.

Found the script from this blog [url]

View 7 Replies View Related

General :: String Replace In Filenames - Files Already Contain The String "Soundtrack"

Jun 11, 2011

Moving right along, I have a folder of MP3 files containing various Movie sound tracks and scores. I'm using Audio Tag Tool to tag all the files at once with an "Artist" of "Soundtrack", and to inherit the "Title" tag from the file name. After that, I will rename all the files (Using Audio Tag Tool -- awesome program, btw) with the format "<Artist> - <Title>.mp3"

The problem, is many of my files already contain the string "Soundtrack", which would be redundant. I happen to be a perfectionist, so I'm unable to ignore it and move on. Hence my question to you fine folk: I want to delete all instances of "soundtrack" (-i case irrelevant) in the filenames before I go through the above steps. But, its not quite that simple. This is a sample of some of the file names:

[Code]....

View 3 Replies View Related

Programming :: Replace All Digits With Symbol In String?

Aug 29, 2010

I am trying to replacee all digits with a symbol (say, big U here) in a string by

[code]...

The result become 'UsUoUmUeUtUhUiUnUgU' instead of 'somethingUUU' as expected. Looks like my string contains some 'hidden digits' in between the letters. Does anyone have an idea about that?

View 2 Replies View Related

Programming :: Replace 2nd Occurrence Of A String In A File - Sed Or Awk?

Apr 5, 2010

I know how to replace a particular instance (say 3rd one) of a word in a line using sed based on the sed one-liners. However I would like to replace a particular instance of a word in the entire file.

For example, here is a file:

Code:
John
Betty
Jack
Ron
Jack
Paul

So now I would like to replace the second instance of Jack (in red color) with "Rob" (for example). Not quite sure how to do that? I tried couple of things from here but they did not work.

View 10 Replies View Related

Programming :: Replace String In File Using Perl Or Sed

Jun 30, 2011

I have question about replacing a string in a file.

How can I replace the printerb's 10.1.1.1 to something else(10.1.1.2, for example) without replace printera's 10.1.1.1 accidentally?

I have tried perl -e -pi "s/10.1.1.1/10.1.1.2/g" /etc/hosts. but, perl replace both 10.1.1.1 to 10.1.1.2.

View 13 Replies View Related

Programming :: Replace String By Incrementing Number

May 30, 2011

Say I have a file as

[code]....

It would be great, if i could issue a command (Vi/Bash/awk, ...) in order to obtain

[Code]...

So, the "replace string" should be replaced by another string containing the counter of replacement.

View 7 Replies View Related

Programming :: Replace Occurrence Of A String In Many Files In One Command?

Oct 30, 2010

I used a command Code:

grep -r err_sys ./
its output is
Code:
./tcpclitime.c:err_sys("socket error");
./tcpclitime.c:err_sys("connect error");
./tcpclitime.c:err_sys("write error");
./tcpclitime.c:err_sys("shutdown error");
./tcpclitime.c:err_sys("read error, n = %d", n);
[Code].....

Is it possible some how to replace all the occurrences of word err_sys by printf.

View 1 Replies View Related

Programming :: Retrieve A Single String Or Value From /proc/cpuinfo

Oct 1, 2010

I'm trying to retrieve a single string or value from /proc/cpuinfo, but when I try to extract the model (not the model name) the model name comes with it, also it likes to print it twice...

Code:
model="`cat /proc/cpuinfo | grep model | cut -d: -f2 | cut -c1-3`"
echo $model

All i want this to do is spit out the model number once. (I need to pass it to another script)

View 14 Replies View Related

Programming :: Python - String To Omit The Single Quotes (')?

Mar 18, 2011

After I assign a string to a variable, I know that the print function will remove the single quotes around the value, but is there a way to assign a variable without the quotes around the value? for example:

a = open('/usr/lib', 'r+')
b = f.read()
c = x.replace('.xx','yy')
d = ?

c returns the value with quotes around it print c returns the value without the quotes Is there a way to assign a new variable (d) which will equal c without the quotes? I need a new variable which has the quotes omitted because from there the script will take the value of the last variable (which is a path to a file), and tar up that file. It won't recognize the path to the file if the value has quotes around it.

View 1 Replies View Related

Programming :: Creates String Suffixes Out Of A Reference String?

Feb 25, 2011

I need to creates string suffixes out of a Reference string. for eg. suffixes of abcdefg will be

1)bcdefg
2)cdefg
3)defg
and so on...

create an array of pointers to point to the first few characters and then use that pointer to print the rest of the string.But when i print using the pointer i get GARBAGE values! shudn't std::cout<<ptr[w] print the string following the char it is pointing to? why do i get garbage values?

View 9 Replies View Related

Programming :: C - Put A Specific Arbitrary Part Of A String Into It's Own String?

Apr 18, 2010

So if I'm given a location of a file like:

How can I just take the type of the file at the end? I know I can use strrchr() for a period to get the pointer to the period just before file type. Is there a build in string function that will just take the rest of the string from a certain point on forward in the string? I know it wouldn't be much work to make it myself, but I figured I would find out if it already existed before doing it.

View 9 Replies View Related

Programming :: Convert String To Integer Back To String C++ ?

Mar 13, 2010

Code:

The error is:

Code:

What I want to do is take input of ip4 as a string, convert it to an integer to add 1 to it, then reconvert it back to a string. Its not working.

My full code is:

Code:

View 1 Replies View Related

Programming :: Text File Replace Occurrences Of Three Character String ZZZ With Quotation Mark

Mar 30, 2010

I want to use SED to do the following: In a text file replace any occurrences of the three character string ZZZ with a quotation mark "and. replace all occurrences of a comma with a semi-colon. It is the S/ / / command which is stumping me on the first issue...inparticular how to get the replace string to be quote.

View 9 Replies View Related

Programming :: Find And Replace A String In A File Using Perl Command From Bash Script?

Feb 14, 2011

I wanted to find and replace a string from a perl file. I have written a script in bash which runs the following command.

perl -pi -e "s/$findstring/$replacestring/" testfile
where as $findstring = print F_WC_TMP"$line
";
and $replaceString = $line = join ' ', split ' ', $line; print F_WC_TMP"$line
";

But when I am running the above command, i think it is replacing the $findstring with the above mentioned string and hence it contains a $line, it is looking for the variable $line and not finding the exact string. I am confused about how to search for a string that contains $ in it and replace it with another $string.

View 5 Replies View Related

Programming :: String Editing: Remove Lines Consisting Of A Single Character?

Jul 16, 2010

I have a large text file that's formatted sort of like this:

Code:
foo bar
blah

[code]...

View 2 Replies View Related

Programming :: Assigning Custom String To Std::string In C++?

Oct 12, 2009

I've been given a custom-made string class which handles string, wstring and bstr. It has a number of methods and assignment operators to convert to and from different types. The app I work on compiles happily in VS6 and VS2008, but when trying to compile in Redhat (version 4.1.1 in Redhat 5.0)

[code]....

View 4 Replies View Related

Programming :: How To Check If All Letters Of One String Are In Another String?

Nov 11, 2010

I have the following two type of strings1: A/D2: A/C/DI am trying to write a subroutine to check whether all of the letters in string 1 appears in string 2. If yes, return true. If not, return false. In the above example, all the letters (A and D) in string 1 are also present in string 2, so I return true.

View 4 Replies View Related

Programming :: Add String On The Beginning And End Of The Line ?

Aug 3, 2010

I need to output of a script to a file with tags.

I'm trying sed and was able to put a tag on the end of the line

Code:

Output is

Quote:

What I need to have is

Quote:

I'm thinking of I redirect my first sed command to a file and then use sed again to put <group> at the beginning of the line. My problem is how to put <group> to all beginning of the string.

View 2 Replies View Related







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