Programming :: Sed To Change Character In Text File Only Once?

Sep 7, 2009

I have a script that looks like:

Code:

cat servers.txt
trivia:P:N
trivia:D:N
tucana:P:Y

[code]....

I want to be able to find the lines that matches my input and change the N to a Y, but only for the lines that matches the name and not any other N's My problem is the line does not always contain a P as it can be a D as well so my matching did not work. If my script issues the name $1=triva the lines will change to:

Code:

trivia:P:Y
trivia:D:Y

I have the following code so far but as you can see it does not change the D's

Code:

sed -i 's/trivia:P:Y/trivia:P:N/g' servers.txt

*** UPDATE ***

should I be using a method as follows? I am still stuck on the changing all instances though.

Code:

$1=server
sed -i 's/$server1:P:Y/$server:P:N/g' server.txt
sed -i 's/$server1:D:Y/$server:D:N/g' server.txt

View 7 Replies


ADVERTISEMENT

Programming :: C++ Character Search In Text File?

Jun 23, 2011

Im trying to read a file in c++ and search for particular character for example if this is a list that I have:

Alice
Bob
David

[code]....

if the input is D, it should give David, if its B, gives bob. so in this case, meaning it reads the first character of every line. but if possible I want to make this dynamic so the user can specify which character position he is looking for, so in case he is looking for R as character index 3 in all lines, it should give Charlie. but the problem is, it does now recognize , besides, I do not know how to specify the character position in each line.

here is my code

Code:

#include <iostream>
#include <fstream>
#include <cstring>

[code]....

View 1 Replies View Related

Programming :: Bash Scripting - Parsing Text File By Character

Aug 11, 2009

Is there a way to process individual characters one-by-one from a text file in Bash, or is that hoping for a little too much from this lovable old clunker?

View 13 Replies View Related

Programming :: Shell Script Comparison For Two File(text) Character Wise?

Mar 1, 2010

I need to write a shell script which can compare two files(text files) character wise. eg. underscore is space.

------FILE 1---------------
A_B_C
D_E_F
G_H_I

[code].....

Actual problem: I need to write a shell script which can give me difference character by character not by line (using comm)

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

Software :: Vim Text Change Command Including X Character

Jun 18, 2011

In Vim, I can change the text up until the next instance of "X" using this command:
Code:
cfX
The problem is that it includes "X". What if I want to change until, but not including, "X"?

View 2 Replies View Related

Programming :: Change Info In A Text File Using C++?

Jan 16, 2011

how to work properly on the windows forms application in c++.

the thing is that i was able to produce in the windows forms application a web browser and I added a save button. So know I am able to navigate predeclared webpages such as [URL]and then I entered google's search box such as "spread of H1N1". and I surf a page such as [URL] I later save the page as text file on my computer.

I wanted to know how to organize the words in the text file ? i mean how can i just get the number of infected people in USA , number of infected in CANADA (if they exist) from all the text file and change it to a file with precise data.that is to eliminate the unneeded information such as the the characteristics and the useless ideas? and what if i also wanted to know the characteristics of the virus in a country+the number of infected?. How can i do it?

View 3 Replies View Related

Programming :: Add A Character To The End Of A Line When A Certain Match Text Is Matched?

Nov 5, 2010

Is there any way to add a character to the end of a line when a certain match text is matched. I have a text file where any line that contacts text XYZ a z is placed at the end.

View 1 Replies View Related

Software :: Deleting All Instances Of A Certain Character From A Text File?

Feb 18, 2010

In my command prompt I did:

Code:

sed 's/://' mytextfile > newtextfile

But it only deleted the first instance of : in each line when some lines have multiple : appearing in each one. How can I delete all the : from the entire file?

View 6 Replies View Related

General :: Change File Character Set?

Aug 9, 2010

I would like to know how I can change a file so it has the same character encoding as files saved as comma separated csv files from Microsoft Excel.

I have tried using iconv to do this. code...

View 5 Replies View Related

Programming :: Perl Regular Expression To Change Character

May 26, 2009

Part of a perl script I am writing need to change the character at an index to upper case. Now i am new to perl and i am having some trouble getting it to do it. In c++ i would do something like

Code:

Now from what i understand the same thing is possible in perl using regular expressions. But i cant get it to work.

View 2 Replies View Related

Programming :: Remove Lines In A Text File Based On Another Text File?

Jan 28, 2009

I have a text file called file1.txt containing many lines eg.

line1
line2
line3
line4
line5
line6

Then i have another text file called file2.txt contains

3
5
6

Is there a command to remove the lines in file1.txt based on the keywords in file2.txt? note: It should remove line3,line5,line6 based on 3,5,6

View 10 Replies View Related

Red Hat / Fedora :: Change File Names To Remove Invalid Character

Apr 1, 2009

I am trying to copy a large number of files from a Linux server to a Windows file share. Unfortunately, all of the files and folders I have to copy have 10 numbers followed by 2 colons "::" in the name (example: 1234567890::WordDoc.doc) which of course is invalid in windows naming conventions. So now I'm trying to come up with a way to change the file and folder names on the fly to replace the colons with a dash "-" or space " ". I'm even willing delete the frist 12 characters in necessary. I have tried cp, mv, tr, and several -bash scripts but get no positive results.

View 4 Replies View Related

Programming :: Check .xml File And Which Character Is Malformed In 'utf-8'?

Jun 15, 2011

I need some software that will check .xml file and tell me which character is malformed in 'utf-8'. I am using perl for some parsing.

View 2 Replies View Related

Programming :: Adding Lines Of Text To Beginning Of Text File

Jan 19, 2009

I need to insert 3-4 lines of text to the beginning of a text file. The file is a largish MYSQL dump, the result of a backup shell script. This shell script should insert the required text.I've wrestled with sed, but lost.

View 2 Replies View Related

Programming :: Delete Line Of Text From Text File Via Shell?

Jan 13, 2010

I have to delete a certain line of text from the a textfile via ubuntu's shell scripting.I have done research, and it seems that most people advocate the usage of sed /d option. sed makes does not edit the text file. Hence, most options I discovered involved the use of a temporary variable/textfile and then overwriting the old file with the temporary new file. Is there anyway whereby I can bypass the use of temporary storage containers? I hope there is any magical combination of commands to edit the file directly.

View 3 Replies View Related

Programming :: Exporting Glade Text View To Text File?

Jan 8, 2011

I want to display something in my text view widget in glade using c code. that's all right.
now I need to attach a save button beneath the text view.so that on click the text view content should save as a txt file..

View 8 Replies View Related

Programming :: Formatting Fields And Text Being Displayed From Text File?

Feb 9, 2011

I want to display the contents of a particular log file (simple text file, I mean in Linux). But there is a problem: The contents need to be organized in a fixed format. Have a look at this log file:

sampleLog.txt

Code:

User Name: XYZ
Reported Problems Description: Blah! Blah! Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah!

[code]....

So, while displaying the contents of above file on a web page, I want to format the field names found in the log file: User Name:, Reported Problems Description:, and Remarks:. These fields may contain a variable length of text and no specific line number is assumed for them to appear on.

The desired output should look like this:

User Name: XYZ
Reported Problems Description: Blah! Blah! Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah!

[code]....

Well, what I am trying to do may sound wierd to some of you. The filed "Reported Problems Description:" can possible contain text which embeds colon (.

View 15 Replies View Related

Programming :: Add Text Before Line Number In Text File?

May 3, 2010

a sed command to add a text before line number in text file? I have text file with 500 lines, and i want to add 3 more lines with text after line 300, OR before line 302, isn't no problem.

View 16 Replies View Related

General :: Change Password Using A Script File And Text File?

Jun 26, 2011

This is for educational purpose. In fact it is my lab tutorial for a subject.I want to capture the users password when he changes his password. Both new and old.This is the script i have come up with:

Code:
#!/bin/bash
echo "Changing password for user $USER."

[code]...

View 5 Replies View Related

Programming :: Change / LINK Text To Yellow , White , Red?

Apr 25, 2009

Can anyone tell me how to change the LINK text to yellow or white or red??
The page is ( http://www.multidistro.com ) code...

View 5 Replies View Related

General :: Use The Man / Info / Apropos Pages - Character Instructed The Shell To Interpret A Special Character As An Ordinary Character?

Mar 27, 2010

1.What character instructd the shell to interpret a special character as an ordinary character?

2.What directory contains some of the utilities available on the system in the form of binary files?

3. What command is used to search the location of a utility?

4. What command is used to instruct the editor to write the file and quit the editor?

5. What key quits the more utility and displays the shell prompt?

6. What command starts a child shell as the super user, taking on root's identity and environment?

7. Which wildcard characters can be used for searching all the files in the system that start with "A"?

8. The user name or login name of the super user is????

[Code]....

View 10 Replies View Related

Programming :: Script To Copy Paste Text From One File To Another (overwriting Part Of The File)?

Apr 19, 2011

I have a .txt-file with ~50.000 lines of numbers, generated by a mathematics program. From this file, I need line ~ 1.100 to line ~16.000 (these lines are always the same btw, this may make the solution easier, dunno) to be copy/pasted to another file, where the lines ~500 to ~15.000 (also, every time the same) should be overwritten by the aforementioned lines...I haven't found or come up with anything that works yet, mostly I find solutions to copy everything from one file to another but I can't find something to specifically overwrite a part of a file with part of another.

View 4 Replies View Related

General :: Change Some Text In File Thunderbird Using Vim?

Mar 21, 2011

i have a file thunderbird which size 1.57GB, that files contain the email that had been deleted but fortunately not been compact so i still can retrive the email that had been deleted the problem the superior not give me the specific of the subject or date on the file.

Code:

X-Mozilla-Status: 0001(this number sometimes not same)
X-Mozilla-Status2: 0000080(this number sometimes not same)

what i need is change the contain number 0001 to 0 in X-Mozilla-Status not the X-Mozilla-Status2, is there any way to do, and the file contain so much text like that so i want to change automatically.

View 5 Replies View Related

Programming :: Create A Duplicate File Of A Text File In PHP?

Nov 11, 2010

What I plan to do is, create a duplicate file of a text file, and then append some text into the new text file.

View 1 Replies View Related

General :: Change All Number 10 In A Text File To Word Form?

Mar 20, 2011

I need to change all number 10 in a text file to word form, or in short from 10->ten. the thing is number 10 including in dates such as 10/22/1997 or 03-10-2011 should not be changed. im having some trouble because the file contains numbers like "price range from 10-50k".

this is just a sample.

name: john smith
birthday: 10-11-1995
date hired: 05/10/2010
expected salary: 10-50k
typing speed: 10 wpm

[Code].....

Using sed command is it possible to change like this..

View 11 Replies View Related

Programming :: Script To Remove Lines In A File With More Than "x" Instances Of Any Character ?

Oct 4, 2010

I'm looking for a script (bash, python, perl etc) or even a one liner (sed, awk etc) that can take a set of files and remove any line that has more than "x" instances of any character (case sensitive). I have been doing a lot of searching and can only come up with examples of how to remove blank lines, lines that start with a certain character or lines that contain a certain string. This will be used on a system running a Kubuntu derivative.

As a very poor and basic example, I would like to take files that contain lines like:

Code:

And end up with the files only containing the lines:

Code:

If I tell the script that 2 is the maximun number of times any character can appear in any line.

I know this must be possible, but for the life of me I cannot find even an example that will lead me in the right direction or better yet a piece of code I can use.

View 15 Replies View Related

Ubuntu :: When Delete Simple Text File / Trash Icon Not Change

Mar 6, 2011

I have installed KDE 4.6.1, on distribution Ubuntu 10.10 . But i have problem with trash icon. Even when i delete a simple text file, trash icon not change, shows empty icon. When I open trash directory location from dolphin, left side shortcuts, it shows empty directory.Is it a bug? Where is my deleted file gone?

View 4 Replies View Related

Fedora :: Delete Character MS-DOS Text Files On System?

Aug 17, 2011

We had seen some time ago, various tricks to remove the character MS-DOS text files on Linux. Here is a new trick to do this directly from the vim editor.
to convert a file opened with vim in UNIX format, simply use the following command code...

View 2 Replies View Related

General :: Insert Character Code Into Text Editor?

Aug 11, 2010

I need a lightweight GUI text editor on my Ubuntu Lucid system which lets me specify a Unicode code point (e.g. U+1234), and inserts that character to a UTF-8 text document. I know that gedit can't do it (not even with the Character Map plugin).

I'm not interested in solutions involving any kind of emacs or vi. I'm also not interested in text editors running in the terminal (such as joe, which has this functionality). I need the absolute simplest, smallest and fastest plain text editor for Linux which lets me type a few letters, insert a few characters by their code, type some more letters, and then save the .txt file as UTF-8-encoded.

View 1 Replies View Related







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