Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Any way to get rid of ^M characters in a text file using pr? Post 302568225 by Nonito84 on Wednesday 26th of October 2011 05:28:47 PM
Old 10-26-2011
Any way to get rid of ^M characters in a text file using pr?

When I use vi to see what's in the file I get this:

Code:
int add1(int x) {^M     return x + 1;^M}
^Mint subtract1(int x) {^M      return x - 1;^M}
^Mint double_it(int x) {^M      return x * 2;^M}
^Mint halve_it(int x) {^Mreturn x / 2;^M}
^Mint main() {^M        int myint;^M    int result;^M   scanf("%d", &myint);^M  if (myint >= 0) {^M             if (myint <= 10) {^M                    result = halve_it(myint);^M             } else {^M                      result = double_it(myint);^M            }^M     } else {^M              if (myint > -10) {^M                    result = subtract1(myint);^M            } else if (myint > -20) {^M                     result = add1(myint);^M         } else {^M                      result = 3;^M           }
^M      return result;^M}

Also tried pr to print the contents to screen it's not working...maybe i'm missing an option?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

getting rid of control characters

how can i get rid of the control characters , ex. ^M, ^G, in a file? thanks... (2 Replies)
Discussion started by: apalex
2 Replies

2. UNIX for Dummies Questions & Answers

unix -> pc (get rid of the funy characters)

I man a command and save it in a file. ftp to pc. but when i displayed it. it has some repeat and funny characters. how can i get rid of it? eg. $ man ls > lsman then use ftp transfer the file from unix to pc. open file laman. it has some thing like NNNNAAAAMMMMEEEE repeat letters... (4 Replies)
Discussion started by: gusla
4 Replies

3. Shell Programming and Scripting

how to get rid of blank line in a flat text file

Hi, I have a flat text file which contains blank line between each text line. Is there any command to get rid of it? Thanks for your help (11 Replies)
Discussion started by: xfang
11 Replies

4. UNIX and Linux Applications

get rid of special characters

Hi Friends, we have recently installed RHEL4.4 and when i give the commd ls -l > tt it prints the file name with some special charactes like ^[[00m1 in the begining of the file name and at the end of the file name. I wanted to use the file names of removing it before taking the backup and... (4 Replies)
Discussion started by: vakharia Mahesh
4 Replies

5. UNIX for Dummies Questions & Answers

Need help getting rid of bold characters

Hi! So i've got this shell script that asks questions and the user is required to input answers. The answers typed are bold. sh-*.*$ sh filename dir cat question tput bold read ans tput sgr0 ... and so on tput sgr0 exit So when the script ends i don't get the bold characters... (3 Replies)
Discussion started by: Kingzy
3 Replies

6. Shell Programming and Scripting

Getting rid of non-numeric and non-characters

I have a database script that always produces the following output: 0 btw, the unwanted character looks like a square on a unix system. it doesn't look like the above quote. how can I get rid of it and only keep the "0"? ---------- Post updated at 01:57 PM ---------- Previous update was... (2 Replies)
Discussion started by: SkySmart
2 Replies

7. Shell Programming and Scripting

get rid of non-alphanumeric characters

Hi! Could anyone so kindly help me a code to eliminate from a txt file, obtained by collecting and merge several web-page, every word (string) containing non alphabetical, numeric and punctuation character (i.e NON a-zA-Z0-9, underscore and punctuation mark)? Thanks a lot for the help to... (5 Replies)
Discussion started by: mjomba
5 Replies

8. Shell Programming and Scripting

Getting rid of abnormal Characters

ok, so i have no clue why this script i wrote spits out these bizarre characters: i cant even copy and paste those characters on here because it just doesn't show up properly. my question is, using sed, how can i get rid of all characters that aren't normal? echo "abnormal characters" |... (4 Replies)
Discussion started by: SkySmart
4 Replies

9. UNIX for Dummies Questions & Answers

Getting rid of abnormal Characters

i'm grepping for words in the /var/adm/messages (sun solaris). but it looks like while my grepping finds the strings, when it outputs them out, the beginning of some lines are chopped off. Jun 13 14:06:02 sky.net ufs: NOTICE: alloc: /prod: file system full 3 14:39:19 sky.net ufs: NOTICE:... (1 Reply)
Discussion started by: SkySmart
1 Replies

10. Shell Programming and Scripting

sed to get rid of unwanted characters

so i have strings such as this: 'postfix/local#2,5#|CRON.*12062.*root.*CMD#2,5#|roice.*NQN1#1,2#|toysprc#1,4#' i need to get rid of the "#" and the numbers between them for each of the strings above. so the desired output should be: ... (1 Reply)
Discussion started by: SkySmart
1 Replies
PERLPRAGMA(1)						 Perl Programmers Reference Guide					     PERLPRAGMA(1)

NAME
perlpragma - how to write a user pragma DESCRIPTION
A pragma is a module which influences some aspect of the compile time or run time behaviour of Perl, such as "strict" or "warnings". With Perl 5.10 you are no longer limited to the built in pragmata; you can now create user pragmata that modify the behaviour of user functions within a lexical scope. A basic example For example, say you need to create a class implementing overloaded mathematical operators, and would like to provide your own pragma that functions much like "use integer;" You'd like this code use MyMaths; my $l = MyMaths->new(1.2); my $r = MyMaths->new(3.4); print "A: ", $l + $r, " "; use myint; print "B: ", $l + $r, " "; { no myint; print "C: ", $l + $r, " "; } print "D: ", $l + $r, " "; no myint; print "E: ", $l + $r, " "; to give the output A: 4.6 B: 4 C: 4.6 D: 4 E: 4.6 i.e., where "use myint;" is in effect, addition operations are forced to integer, whereas by default they are not, with the default behaviour being restored via "no myint;" The minimal implementation of the package "MyMaths" would be something like this: package MyMaths; use warnings; use strict; use myint(); use overload '+' => sub { my ($l, $r) = @_; # Pass 1 to check up one call level from here if (myint::in_effect(1)) { int($$l) + int($$r); } else { $$l + $$r; } }; sub new { my ($class, $value) = @_; bless $value, $class; } 1; Note how we load the user pragma "myint" with an empty list "()" to prevent its "import" being called. The interaction with the Perl compilation happens inside package "myint": package myint; use strict; use warnings; sub import { $^H{"myint/in_effect"} = 1; } sub unimport { $^H{"myint/in_effect"} = 0; } sub in_effect { my $level = shift // 0; my $hinthash = (caller($level))[10]; return $hinthash->{"myint/in_effect"}; } 1; As pragmata are implemented as modules, like any other module, "use myint;" becomes BEGIN { require myint; myint->import(); } and "no myint;" is BEGIN { require myint; myint->unimport(); } Hence the "import" and "unimport" routines are called at compile time for the user's code. User pragmata store their state by writing to the magical hash "%^H", hence these two routines manipulate it. The state information in "%^H" is stored in the optree, and can be retrieved read-only at runtime with "caller()", at index 10 of the list of returned results. In the example pragma, retrieval is encapsulated into the routine "in_effect()", which takes as parameter the number of call frames to go up to find the value of the pragma in the user's script. This uses "caller()" to determine the value of $^H{"myint/in_effect"} when each line of the user's script was called, and therefore provide the correct semantics in the subroutine implementing the overloaded addition. Key naming There is only a single "%^H", but arbitrarily many modules that want to use its scoping semantics. To avoid stepping on each other's toes, they need to be sure to use different keys in the hash. It is therefore conventional for a module to use only keys that begin with the module's name (the name of its main package) and a "/" character. After this module-identifying prefix, the rest of the key is entirely up to the module: it may include any characters whatsoever. For example, a module "Foo::Bar" should use keys such as "Foo::Bar/baz" and "Foo::Bar/$%/_!". Modules following this convention all play nicely with each other. The Perl core uses a handful of keys in "%^H" which do not follow this convention, because they predate it. Keys that follow the convention won't conflict with the core's historical keys. Implementation details The optree is shared between threads. This means there is a possibility that the optree will outlive the particular thread (and therefore the interpreter instance) that created it, so true Perl scalars cannot be stored in the optree. Instead a compact form is used, which can only store values that are integers (signed and unsigned), strings or "undef" - references and floating point values are stringified. If you need to store multiple values or complex structures, you should serialise them, for example with "pack". The deletion of a hash key from "%^H" is recorded, and as ever can be distinguished from the existence of a key with value "undef" with "exists". Don't attempt to store references to data structures as integers which are retrieved via "caller" and converted back, as this will not be threadsafe. Accesses would be to the structure without locking (which is not safe for Perl's scalars), and either the structure has to leak, or it has to be freed when its creating thread terminates, which may be before the optree referencing it is deleted, if other threads outlive it. perl v5.16.3 2013-03-04 PERLPRAGMA(1)
All times are GMT -4. The time now is 12:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy