03-25-2006
String Search & Replace
Hey, I want to have a C program which, for an existing file supplied by the command line argument (E.g. File1.txt) replaces all the occurrences of the words:
"We” or “we” by “I”
“a” by “the”
“A” by “The”.
Then print the replaced file. All other characters of the file are to be left unchanged.
I know basically to change a string of characters you use:
String.Replace("oldval","newval");
How would you go about doing this to an entire txt file???
Maybe use a loop or case statement?
Does anybody know any places to get code snippets for something like this.
Im not very experienced but looking to learn!!
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Is there any way we can achieve search & replace with awk?
I could achieve the same with sed in following way -
sed 's/A/B/g' file1 > file2
But the same regex if I try with using awk following way,
awk 's/A/B/g' file1 > file2
it gives me Syntax error. I strongly believe I am... (1 Reply)
Discussion started by: videsh77
1 Replies
2. Shell Programming and Scripting
Hello all
i have big test file that has allot of structure text something like this :
<foo1 *.html>
<blah action>
somthing 1
somthing 2
</blah>
</foo1 >
now i will like to insert 2 more lines of text below the <blah action>
so it will be like :
<foo1... (1 Reply)
Discussion started by: umen
1 Replies
3. UNIX for Dummies Questions & Answers
I want to carry out search & replace for the paths mentioned in the file with the help of vi.
'abc/' to be replaced by 'abc/data'
When I use command in vi as below -
%s/abc//abc/data/g
it gives me an error.
How we should deal with '/' part in string for vi search & replace?
... (6 Replies)
Discussion started by: videsh77
6 Replies
4. Shell Programming and Scripting
Hi All,
I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text.
An example of 4 lines in my file is:
1. MatchText_randomNumberOfText moreData ReplaceMe moreData
2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
5. UNIX for Dummies Questions & Answers
Hi ,
I ahve a text file which has several instances of the text such as
run_time: 09:30
I need to add double quotes before and after the time value
i.e: run_time: "09:30"
Any suggestions on how to go about the same (4 Replies)
Discussion started by: jobbyjoseph
4 Replies
6. Shell Programming and Scripting
Hi All,
How do I search first string & second string and copy all content between them from one file to another file?
Please help me..
Thanks In Advance.
Regards,
Pankaj (12 Replies)
Discussion started by: pankajp
12 Replies
7. Shell Programming and Scripting
Hello: I have another question. Please consider the following two sample, tab-delimited files:
File_1:
Abf1 YKL112w
Abf1 YAL054c
Abf1 YGL234w
Ace2 YKL150w
Ace2 YNL328c
Cup9 YDR441c
Cup9 YDR442w
Cup9 YEL040w
...
File 2:
...
ABF1 YKL112W
ACE2 YLR131C (9 Replies)
Discussion started by: gstuart
9 Replies
8. Shell Programming and Scripting
Hello,
I really would appreciate some help with a bash script for some string manipulation on an SQL dump:
I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump.
This is quite easy with sed:
sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies
9. Shell Programming and Scripting
find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g'
this is simple logic to find and replace in multiple files & folders
Hope this helps.
Thanks
Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies
10. Shell Programming and Scripting
Hi all.
I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value.
cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile
This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies
LEARN ABOUT REDHAT
wrjpgcom
WRJPGCOM(1) General Commands Manual WRJPGCOM(1)
NAME
wrjpgcom - insert text comments into a JPEG file
SYNOPSIS
wrjpgcom [ -replace ] [ -comment text ] [ -cfile name ] [ filename ]
DESCRIPTION
wrjpgcom reads the named JPEG/JFIF file, or the standard input if no file is named, and generates a new JPEG/JFIF file on standard output.
A comment block is added to the file.
The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file. Although the standard doesn't actually define what COM blocks
are for, they are widely used to hold user-supplied text strings. This lets you add annotations, titles, index terms, etc to your JPEG
files, and later retrieve them as text. COM blocks do not interfere with the image stored in the JPEG file. The maximum size of a COM
block is 64K, but you can have as many of them as you like in one JPEG file.
wrjpgcom adds a COM block, containing text you provide, to a JPEG file. Ordinarily, the COM block is added after any existing COM blocks;
but you can delete the old COM blocks if you wish.
OPTIONS
Switch names may be abbreviated, and are not case sensitive.
-replace
Delete any existing COM blocks from the file.
-comment text
Supply text for new COM block on command line.
-cfile name
Read text for new COM block from named file.
If you have only one line of comment text to add, you can provide it on the command line with -comment. The comment text must be sur-
rounded with quotes so that it is treated as a single argument. Longer comments can be read from a text file.
If you give neither -comment nor -cfile, then wrjpgcom will read the comment text from standard input. (In this case an input image file
name MUST be supplied, so that the source JPEG file comes from somewhere else.) You can enter multiple lines, up to 64KB worth. Type an
end-of-file indicator (usually control-D) to terminate the comment text entry.
wrjpgcom will not add a COM block if the provided comment string is empty. Therefore -replace -comment "" can be used to delete all COM
blocks from a file.
EXAMPLES
Add a short comment to in.jpg, producing out.jpg:
wrjpgcom -c "View of my back yard" in.jpg > out.jpg
Attach a long comment previously stored in comment.txt:
wrjpgcom in.jpg < comment.txt > out.jpg
or equivalently
wrjpgcom -cfile comment.txt < in.jpg > out.jpg
SEE ALSO
cjpeg(1), djpeg(1), jpegtran(1), rdjpgcom(1)
AUTHOR
Independent JPEG Group
15 June 1995 WRJPGCOM(1)