Weird characters when reading out a file line by line [duplicate]












0
















This question already has an answer here:




  • Remove carriage return in Unix

    16 answers



  • Are shell scripts sensitive to encoding and line endings?

    2 answers




I have a file containing paths to certain other files.



Now I want to read out this file line by line and call a function on each path specified.



#!/bin/bash
mkdir dest
while IFS='' read -r line || [[ -n "$line" ]]; do
mv "$line" dest/
done < input_file


and my input file looks like this:



./data/f1
./data/f2
./data/f3


But I get this error:



mv: cannot stat './data/f3'$'r': No such file or directory
mv: cannot stat './data/f3'$'r': No such file or directory
mv: cannot stat './data/f3'$'r': No such file or directory


I couldn't figure out what these special symbols in the end mean.










share|improve this question















marked as duplicate by chepner, kvantour, Jens bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 18:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 2





    input_file has DOS line breaks. You can remove it using dos2unix or sed

    – anubhava
    Nov 14 '18 at 16:14











  • related: stackoverflow.com/questions/45772525/…

    – kvantour
    Nov 14 '18 at 16:18











  • I thought there used to be a relevant duplicate listed in the bash tag wiki, but it doesn't appear to be there any more.

    – chepner
    Nov 14 '18 at 16:19











  • Also, if you fix input_file to be a proper POSIX text file, you can get rid of the || [ -n "$line" ]] hack.

    – chepner
    Nov 14 '18 at 16:26






  • 1





    See the "Before asking about problematic code" section of the Stack Overflow 'bash' Info page.

    – pjh
    Nov 14 '18 at 17:02
















0
















This question already has an answer here:




  • Remove carriage return in Unix

    16 answers



  • Are shell scripts sensitive to encoding and line endings?

    2 answers




I have a file containing paths to certain other files.



Now I want to read out this file line by line and call a function on each path specified.



#!/bin/bash
mkdir dest
while IFS='' read -r line || [[ -n "$line" ]]; do
mv "$line" dest/
done < input_file


and my input file looks like this:



./data/f1
./data/f2
./data/f3


But I get this error:



mv: cannot stat './data/f3'$'r': No such file or directory
mv: cannot stat './data/f3'$'r': No such file or directory
mv: cannot stat './data/f3'$'r': No such file or directory


I couldn't figure out what these special symbols in the end mean.










share|improve this question















marked as duplicate by chepner, kvantour, Jens bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 18:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 2





    input_file has DOS line breaks. You can remove it using dos2unix or sed

    – anubhava
    Nov 14 '18 at 16:14











  • related: stackoverflow.com/questions/45772525/…

    – kvantour
    Nov 14 '18 at 16:18











  • I thought there used to be a relevant duplicate listed in the bash tag wiki, but it doesn't appear to be there any more.

    – chepner
    Nov 14 '18 at 16:19











  • Also, if you fix input_file to be a proper POSIX text file, you can get rid of the || [ -n "$line" ]] hack.

    – chepner
    Nov 14 '18 at 16:26






  • 1





    See the "Before asking about problematic code" section of the Stack Overflow 'bash' Info page.

    – pjh
    Nov 14 '18 at 17:02














0












0








0









This question already has an answer here:




  • Remove carriage return in Unix

    16 answers



  • Are shell scripts sensitive to encoding and line endings?

    2 answers




I have a file containing paths to certain other files.



Now I want to read out this file line by line and call a function on each path specified.



#!/bin/bash
mkdir dest
while IFS='' read -r line || [[ -n "$line" ]]; do
mv "$line" dest/
done < input_file


and my input file looks like this:



./data/f1
./data/f2
./data/f3


But I get this error:



mv: cannot stat './data/f3'$'r': No such file or directory
mv: cannot stat './data/f3'$'r': No such file or directory
mv: cannot stat './data/f3'$'r': No such file or directory


I couldn't figure out what these special symbols in the end mean.










share|improve this question

















This question already has an answer here:




  • Remove carriage return in Unix

    16 answers



  • Are shell scripts sensitive to encoding and line endings?

    2 answers




I have a file containing paths to certain other files.



Now I want to read out this file line by line and call a function on each path specified.



#!/bin/bash
mkdir dest
while IFS='' read -r line || [[ -n "$line" ]]; do
mv "$line" dest/
done < input_file


and my input file looks like this:



./data/f1
./data/f2
./data/f3


But I get this error:



mv: cannot stat './data/f3'$'r': No such file or directory
mv: cannot stat './data/f3'$'r': No such file or directory
mv: cannot stat './data/f3'$'r': No such file or directory


I couldn't figure out what these special symbols in the end mean.





This question already has an answer here:




  • Remove carriage return in Unix

    16 answers



  • Are shell scripts sensitive to encoding and line endings?

    2 answers








bash shell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 16:59









kvantour

8,79831330




8,79831330










asked Nov 14 '18 at 16:04









JonasJonas

604829




604829




marked as duplicate by chepner, kvantour, Jens bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 18:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by chepner, kvantour, Jens bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 18:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2





    input_file has DOS line breaks. You can remove it using dos2unix or sed

    – anubhava
    Nov 14 '18 at 16:14











  • related: stackoverflow.com/questions/45772525/…

    – kvantour
    Nov 14 '18 at 16:18











  • I thought there used to be a relevant duplicate listed in the bash tag wiki, but it doesn't appear to be there any more.

    – chepner
    Nov 14 '18 at 16:19











  • Also, if you fix input_file to be a proper POSIX text file, you can get rid of the || [ -n "$line" ]] hack.

    – chepner
    Nov 14 '18 at 16:26






  • 1





    See the "Before asking about problematic code" section of the Stack Overflow 'bash' Info page.

    – pjh
    Nov 14 '18 at 17:02














  • 2





    input_file has DOS line breaks. You can remove it using dos2unix or sed

    – anubhava
    Nov 14 '18 at 16:14











  • related: stackoverflow.com/questions/45772525/…

    – kvantour
    Nov 14 '18 at 16:18











  • I thought there used to be a relevant duplicate listed in the bash tag wiki, but it doesn't appear to be there any more.

    – chepner
    Nov 14 '18 at 16:19











  • Also, if you fix input_file to be a proper POSIX text file, you can get rid of the || [ -n "$line" ]] hack.

    – chepner
    Nov 14 '18 at 16:26






  • 1





    See the "Before asking about problematic code" section of the Stack Overflow 'bash' Info page.

    – pjh
    Nov 14 '18 at 17:02








2




2





input_file has DOS line breaks. You can remove it using dos2unix or sed

– anubhava
Nov 14 '18 at 16:14





input_file has DOS line breaks. You can remove it using dos2unix or sed

– anubhava
Nov 14 '18 at 16:14













related: stackoverflow.com/questions/45772525/…

– kvantour
Nov 14 '18 at 16:18





related: stackoverflow.com/questions/45772525/…

– kvantour
Nov 14 '18 at 16:18













I thought there used to be a relevant duplicate listed in the bash tag wiki, but it doesn't appear to be there any more.

– chepner
Nov 14 '18 at 16:19





I thought there used to be a relevant duplicate listed in the bash tag wiki, but it doesn't appear to be there any more.

– chepner
Nov 14 '18 at 16:19













Also, if you fix input_file to be a proper POSIX text file, you can get rid of the || [ -n "$line" ]] hack.

– chepner
Nov 14 '18 at 16:26





Also, if you fix input_file to be a proper POSIX text file, you can get rid of the || [ -n "$line" ]] hack.

– chepner
Nov 14 '18 at 16:26




1




1





See the "Before asking about problematic code" section of the Stack Overflow 'bash' Info page.

– pjh
Nov 14 '18 at 17:02





See the "Before asking about problematic code" section of the Stack Overflow 'bash' Info page.

– pjh
Nov 14 '18 at 17:02












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python