Hi, in a text file there is a \r wherever a return should be. The
actual returns aren't put in the file because it would complicate the
parsing. However, when I'm done parsing, I put the text in a variable
"result" and I would like to convert all the \r in result to actual
returns. How can I do this? I'm using gsub but I don't know what the
replacement string should be. Thanks for any help with this.
|
|
0
|
|
|
|
Reply
|
dan.j.weber (10)
|
10/29/2005 7:28:03 PM |
|
On 2005-10-29, dan.j.weber@gmail.com wrote:
> Hi, in a text file there is a \r wherever a return should be. The
> actual returns aren't put in the file because it would complicate the
> parsing. However, when I'm done parsing, I put the text in a variable
> "result" and I would like to convert all the \r in result to actual
> returns. How can I do this? I'm using gsub but I don't know what the
> replacement string should be.
"\n"
> Thanks for any help with this.
--
Chris F.A. Johnson | Author:
<http://cfaj.freeshell.org> | Shell Scripting Recipes:
Any code in this post is released | A Problem-Solution Approach,
under the GNU General Public Licence | 2005, Apress
|
|
0
|
|
|
|
Reply
|
Chris
|
10/29/2005 7:40:56 PM
|
|
dan.j.weber@gmail.com wrote:
> Hi, in a text file there is a \r wherever a return should be. The
> actual returns aren't put in the file because it would complicate the
> parsing. However, when I'm done parsing, I put the text in a variable
> "result" and I would like to convert all the \r in result to actual
> returns. How can I do this? I'm using gsub but I don't know what the
> replacement string should be. Thanks for any help with this.
>
It's probably "\n", but maybe all you really need is this:
awk -v RS="\r" '($1=$1)1' file
Post some sampel in/out and what you've tried so far for more suggestions.
Ed.
|
|
0
|
|
|
|
Reply
|
Ed
|
10/29/2005 7:43:40 PM
|
|
dan.j.weber@gmail.com wrote:
> Hi, in a text file there is a \r wherever a return should be. The
> actual returns aren't put in the file because it would complicate the
> parsing. However, when I'm done parsing, I put the text in a variable
> "result" and I would like to convert all the \r in result to actual
> returns. How can I do this? I'm using gsub but I don't know what the
> replacement string should be. Thanks for any help with this.
awk '{gsub(/\\r/, "\r")}8'
|
|
0
|
|
|
|
Reply
|
William
|
10/29/2005 8:21:31 PM
|
|
In article <1130617291.483507.210810@g43g2000cwa.googlegroups.com>,
William James <w_a_x_man@yahoo.com> wrote:
....
>awk '{gsub(/\\r/, "\r")}8'
The {} is unnecessary. 2 stroke penalty.
|
|
0
|
|
|
|
Reply
|
gazelle
|
10/29/2005 8:24:42 PM
|
|
Okay, this worked. Thanks for all your responses. I have one more
question about search/replace and hopefully I won't have to start a new
thread:
I want to replace all ' (apostrophes) with empty strings. However, my
awk code must be typed on the command line. Since awk uses ' to enclose
the code, this doesn't work:
awk -v greeting="what's up" 'BEGIN {gsub("'", "", title); print
greeting}'
I tried escaping the ' with \ but it still halts the code. Any
suggestions?
|
|
0
|
|
|
|
Reply
|
dan
|
10/30/2005 2:22:54 AM
|
|
dan.j.weber@gmail.com wrote:
> Okay, this worked. Thanks for all your responses. I have one more
> question about search/replace and hopefully I won't have to start a new
> thread:
>
> I want to replace all ' (apostrophes) with empty strings. However, my
> awk code must be typed on the command line. Since awk uses ' to enclose
> the code, this doesn't work:
>
> awk -v greeting="what's up" 'BEGIN {gsub("'", "", title); print
> greeting}'
>
> I tried escaping the ' with \ but it still halts the code. Any
> suggestions?
>
$ awk -v greeting="what's up" -v sq=\' 'BEGIN {gsub(sq, "", greeting);
print greeting}'
whats up
Regards,
Ed.
|
|
0
|
|
|
|
Reply
|
Ed
|
10/30/2005 2:42:56 AM
|
|
dan.j.weber@gmail.com writes:
>I want to replace all ' (apostrophes) with empty strings. However, my
>awk code must be typed on the command line. Since awk uses ' to enclose
>the code, this doesn't work:
>
>awk -v greeting="what's up" 'BEGIN {gsub("'", "", title); print
>greeting}'
>
>I tried escaping the ' with \ but it still halts the code. Any
>suggestions?
gsub("\047","",title) where \047 represents the octal code for apostrophe.
Also try:
gawk -v greeting="what's up" 'BEGIN {gsub("'\''", "",greeting); print
greeting}'
--
John Savage (my news address is not valid for email)
|
|
0
|
|
|
|
Reply
|
John
|
11/3/2005 11:31:22 PM
|
|
|
7 Replies
142 Views
(page loaded in 0.108 seconds)
Similiar Articles: Help to 'pretty'; replace WITHIN file without TEMP file?? - comp ...'Day-7' 08152007 Actual lines of the blank are: REPSET RULE ADD "F:\Returns\DATA\Day-0" INC,REC; REPSET ... replace WITHIN file without TEMP file ... sed replace string ... Carriage return in strings - comp.unix.programmerI was trying to just use '\n' within the search and replace string in MATLAB's ... ... C# Carriage Return in string - Toolbox for IT Groups Hie Gurus I am building a string ... Convert getFullYear to 2-digit format - comp.lang.javascript ...getFullYear returns a number, not a string. To use the String object's substring method ... getFullYear() + '').substring(2,4); You could also use the replace ... Replacing an existing jPanel with a new jPanel - comp.lang.java ...My question is: Is it possible to replace the existing ... that > creates a graph (using jFreeChart) and returns the ... class test7 { public static void main(String[] args ... Using regular expressions to split a string - comp.lang.javascript ...A workaround: var s = "one&two\\&three&four"; alert(s.replace(/\\&/g ... contains no ampersands what so ever. eg: "this is string 1" should return just one string ... replace hex sequence - comp.lang.awkI need to replace a sequence of hex characters with awk. ... not do anything. > > Is there a way to match a string of ... However the real application is different, because it ... Insert a string into the text of textarea. Caret? IE question ...... new text - now even when I select say 3 symbols and programmatically replace it with my string ... Return Values from INSERT - comp.databases.mysql Insert a string into the ... Bash Test for Partial Match of String - comp.unix.shellThe return value is 0 if the string matches (==) or does ... the United States that's actual ... Test for Partial Match of String - comp.unix.shell Update Statement - Replace ... special character ' - comp.databases.mysql... sddsd'") >>> the sql query returns an ... posting fixed> Look at mysql_real_escape_string ... situations ? now, via code, i > replace into the "description" > string ... unicode display of common characters - comp.emacs... probably that gedit returns this format when Emacs asks for the STRING ... you gave (with the real ... 9a-fA-F]\\)" nil t) (replace-match (benny-codepoint-to-char (string ... .net - Replace Line Breaks in a String C# - Stack OverflowI needed to replace the \r\n with actual carrige return and line feed and replace \t with actual tab. So I came up witht the following: public string Transform(string ... String.Replace Method (System)Writing test.Replace("1","2"); won't work because test.Replace(string, string); is a method which returns a new string, and does not modify the original string, and so it ... 7/16/2012 3:23:22 PM
|