LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2013, 04:06 AM   #1
eminempark
Member
 
Registered: Oct 2012
Posts: 56

Rep: Reputation: Disabled
running shell script loop


I'm trying to do paste command to combine two files but I want to loop the command. This is my code

Code:
#!/bin/bash
for FNAME in *burst.txt
do
paste -d ' ' burst1.txt $FNAME > "paste_${FNAME#*_}"
done
But it has error. Any help?

Errors:
Code:
./paste.sh: line 3:syntax error near unexpected token '$'do\r''
'/paste.sh: line 3: 'do

Last edited by eminempark; 10-18-2013 at 04:14 AM.
 
Old 10-18-2013, 04:34 AM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
To simply combine two or more files use 'cat', like so:
Code:
cat file1.txt file2.txt > outfile.txt
 
Old 10-18-2013, 04:37 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Are all the files (including the script itself) normal ASCII files?

It looks like the script might not be (the \r part).

The file command might not show the difference, try this instead:
Code:
od -c paste.sh
If \r is shown instead of \n then it is not a regular ASCII file.
 
Old 10-27-2013, 10:15 PM   #4
eminempark
Member
 
Registered: Oct 2012
Posts: 56

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
Are all the files (including the script itself) normal ASCII files?

It looks like the script might not be (the \r part).

The file command might not show the difference, try this instead:
Code:
od -c paste.sh
If \r is shown instead of \n then it is not a regular ASCII file.
It shows
Code:
#!/bin/bash\r\nfor
 FNAME in *burst
.txt\r\ndo\r\npaste 
-d ' ' burst1.tx
t $FNAME > "past
e_${FNAME#*_}"\r\n
done
May I know how to solve the \r?
 
Old 10-27-2013, 11:57 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Install dos2nix and use it on the file or you could re-create the file in linux with an editor there so as to not have the Windows line endings
 
  


Reply

Tags
bash, file, paste, script



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script for each loop s_linux Programming 4 07-02-2013 04:50 PM
Need help with bash shell script for loop Thaidog Programming 6 03-28-2012 08:59 AM
Need help writing for loop shell script hsp40oz Linux - Newbie 38 08-10-2010 07:39 PM
shell script , while loop ykc Programming 5 03-30-2009 07:50 AM
Loop in Shell Script delamatrix Programming 4 07-24-2008 05:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration