![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SED + Regex + SQL Input file | primal | Shell Programming and Scripting | 10 | 04-14-2008 02:24 PM |
| how do you get input of a file to calculations | nadman123 | Shell Programming and Scripting | 6 | 04-11-2008 04:14 AM |
| redirect input from file? | bjornrud | UNIX for Dummies Questions & Answers | 1 | 03-09-2008 02:37 AM |
| Giving input to a c++ file | tonyaim83 | Shell Programming and Scripting | 2 | 10-23-2007 02:10 AM |
| how to get input from file | ajaya | Shell Programming and Scripting | 1 | 04-05-2006 03:02 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
Problem with ^M in input file
Greetings to all,
I have this problem comparing two file and extract the output from it. "input.txt" file(Extracted from excel): ABC ABB ABA "compare.txt" file(Extracted from excel): ABA 1 ABB 2 ABC 3 ABD 4 ABE 5 ABF 6 ABG 7 I would like to get output of ABC 3 ABB 2 ABA 1 This is my script: ----------------- while read record do grep "$record" compare.txt done < input.txt > output.txt The result of `wc -l output.txt` is zero. I later `echo "try" > input.txt and when I `vi input.txt` I found this: ABC^M ABB^M ABA^M try Question: Why is the ^M appearing and how to get rid of it? I tried removing the ^M manually and my output is all NICE. Please advice. Thank you. cheers, -NoeL- |
|
|||||
|
The ^M appears in files that come over from Windows or DOS. This is because the line ending character in Unix is "\n", while in Windows and DOS, you have "\r\n". The "\n" from these is shown as the ^M. For a nice explaination go here. To get rid of these characters, you can use the dos2unix (Solaris) or dos2ux (HP) commands. Or these little perl statements: Code:
# neither of the following perl statements have been tested by me perl -pe 's/\015\012/\n/g' ##- dos to unix -- just pipe through it perl -pe 's/\n/\015\012/g' ##- unix to dos -- just pipe through it Or do what I do: Code:
strings file_to_convert > converted_file; mv converted_file file_to_convert Last edited by blowtorch; 10-24-2005 at 05:49 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|