Removing control-M (^M) from file in AIX/Linux

Removing control-M (^M) from file in AIX/Linux

Method I:-
Below is one liner PERL command for removing ^M from file

perl -p -i -e "s/\r\n/\n/g" file_name

Method II:- Open file in Vi Editor then type below command in "Command Mode"

:%s/^M//g  (To print ^M use ctrl+v and ctrl+m command)

Then save the file with ":wq" 

Rename files which has white space (" ") in it's name with ("_") underscore  :-

find . -type f -name "* *" -exec bash -c 'mv "$0" "${0// /_}"' {} \;  

Adding extension in file name which don't have the extension and name start with GE :-

for i in GE*; do mv $i $i.csv ; done 

Checking duplicate files (Content duplicate) and files name start with GE:-

for i in GE*; 
     do 
          for j in *; 
            do diff $i $j > /dev/null; 
                   if [ $? == "0" ]; then 
                       if [ "$i" != "$j" ]; then 
                          echo "$i,$j are duplicates"; 
                       fi 
                   fi 
            done; 
       done 

Adding files content in one file whose name start with CT and extension of file is .OUT after deletion of 10 lines from head of every files:- 

for i in CT*.OUT ; do sed '1,10d' $i>$i.1 ; cat $i.1>>final.csv ; rm -f $i.1;  done

No comments:

Post a Comment