![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SED + Regex + SQL Input file | primal | Shell Programming and Scripting | 10 | 04-14-2008 10:24 AM |
| how do you get input of a file to calculations | nadman123 | Shell Programming and Scripting | 6 | 04-11-2008 12:14 AM |
| redirect input from file? | bjornrud | UNIX for Dummies Questions & Answers | 1 | 03-08-2008 10:37 PM |
| Giving input to a c++ file | tonyaim83 | Shell Programming and Scripting | 2 | 10-22-2007 10:10 PM |
| how to get input from file | ajaya | Shell Programming and Scripting | 1 | 04-05-2006 11:02 AM |
|
|
Submit Tools | LinkBack | Thread Tools | 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- |
| Forum Sponsor | ||
|
|
|
||||
|
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 Code:
strings file_to_convert > converted_file; mv converted_file file_to_convert Last edited by blowtorch; 10-24-2005 at 01:49 AM. |
| Thread Tools | |
| Display Modes | |
|
|