User Tools

Site Tools


remove_special_chars_from_windows_files

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
remove_special_chars_from_windows_files [2017/07/19 13:43] – created walkeradminremove_special_chars_from_windows_files [2023/03/09 22:35] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Remove Special Chars from Windows files ====== ====== Remove Special Chars from Windows files ======
 +<color #db5f0b>Jul 2017</color>
 +\\ 
 +\\ 
 +
 +----
 +If you have copied any text files or text strings from a Windows PC, then you might find that there are still special characters in this file that stop you executing it as a script on a linux computer. These special characters are typically carriage returns and line feeds.
 +\\ 
 +\\ 
 +Below is a file that I copied from Windows to a CentOS linux server, it dind't matter if I copied the file, or did a copy/paste, the issue still arose. After each line you can see a <color #ed1c24>^M</color> character, which is a Windows carriage return (Linux doesn't use Carriage returns, only line feeds, Windows uses both).
 +\\ 
 +\\ 
 +When you edit the file in vi, you can't see these special characters, you have use another switch with vi to show them. Run vi using a <color #ed1c24>-b</color> switch.
 +\\ 
 +    vi -b filename
 +
 +----
 +
 +#!/bin/bash<color #ed1c24>^M</color>\\ 
 +# Install useful tools<color #ed1c24>^M</color>\\ 
 +<color #ed1c24>^M</color>\\ 
 +yum install epel-release -y<color #ed1c24>^M</color>\\ 
 +yum install htop -y<color #ed1c24>^M</color>\\ 
 +yum install nload -y<color #ed1c24>^M</color>\\ 
 +yum install iperf -y<color #ed1c24>^M</color>\\ 
 +yum install tcpdump -y<color #ed1c24>^M</color>\\ 
 +yum install ncdu -y<color #ed1c24>^M</color>\\ 
 +yum install net-tools -y<color #ed1c24>^M</color>\\ 
 +rpm --import http://packages.atrpms.net/RPM-GPG-KEY.atrpms<color #ed1c24>^M</color>\\ 
 +touch /etc/yum.repos.d/atrpms.repo<color #ed1c24>^M</color>\\ 
 +echo "[atrpms]<color #ed1c24>^M</color>\\ 
 +name=Fedora Core \$releasever - \$basearch - ATrpms<color #ed1c24>^M</color>\\ 
 +baseurl=http://dl.atrpms.net/el\$releasever-\$basearch/atrpms/stable<color #ed1c24>^M</color>\\ 
 +gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms<color #ed1c24>^M</color>\\ 
 +enabled=1<color #ed1c24>^M</color>\\ 
 +gpgcheck=1" > /etc/yum.repos.d/atrpms.repo<color #ed1c24>^M</color>\\ 
 +yum install ffmpeg -y\\ 
 +
 +----
 +You can remove these special characters in Linux using a variety of methods, here are two.
 +\\ 
 +    1. In vi, just delete the ^M characters and save the file.
 +    
 +    2. Install dos2unix (yum install dos2unix) and execute this on your file (dos2unix filename) 
 +       and it will remove them for you, handy if it is a big file.
 +\\ 
remove_special_chars_from_windows_files.1500468224.txt.gz · Last modified: 2023/03/09 22:35 (external edit)