File copying in FOR loop


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers File copying in FOR loop
# 1  
Old 02-15-2012
File copying in FOR loop

Hi,

I am trying to perform a dos2unix conversion for a file. I am doing this in the FOR loop. Below is the command I am using in my script.
$FILE is the file the for loop is processing currently and I would like to convert $FILE and create a $FILE_I

PHP Code:
dos2unix -n $WORK/$FILE $WORK/$FILE_I 
This is not working.. it throws an error that it can't convert the $file and it is creating a dummyfile something like this d2utmpPuto7N and d2utmpaiOzz6 and writing it to that file instead of $FILE_I
should I create a $FILE_I file before executing this dos2unix command or a file called $FILE_I can't be created in the FOR loop??

I have to create such file as the file names, file numbers to be processed all are dynamic.

I also tried copying the $FILE to $FILE_I before dos2unix command but no luck, the error is $FILE and $FILE_I both are same cannot copy...

Can someone throw some light on what is missing?

Thanks!
# 2  
Old 02-15-2012
Not sure what OS and/or shell you're using, but this worked for me:

Code:
for x in file*;do dos2unix -n $x ${x}_new;done
dos2unix: converting file file1 to file file1_new in UNIX format ...
dos2unix: converting file file2 to file file2_new in UNIX format ...
dos2unix: converting file file3 to file file3_new in UNIX format ...
dos2unix: converting file file4 to file file4_new in UNIX format ...
dos2unix: converting file file5 to file file5_new in UNIX format ...

This User Gave Thanks to in2nix4life For This Post:
# 3  
Old 02-15-2012
It always helps to post what Operating System and version you have and what Shell you are using. We can't check your syntax.

Quote:
dos2unix -n $WORK/$FILE $WORK/$FILE_I
Right $FILE and $FILE_I are valid names for two different environment variables.
If you want to append the suffix "_I" to whe filename you need to delimit the variable with curly brackets. It is good practice to do this anyway:
Code:
dos2unix -n ${WORK}/${FILE} ${WORK}/${FILE}_I

If this doesn't fix the issue I'd change the variable names $WORK and $FILE to something less generic in case your "dos2unix" program has some undocumented use of these variables (this sort of problem is more common than people believe).
This User Gave Thanks to methyl For This Post:
# 4  
Old 02-15-2012
thanks in2nix4life and methyl. curly bracket was the issue. I included it and it worked.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying a file to multiple other files using a text file as input

Hello, I have a file called COMPLIST as follows that contains 4 digit numbers.0002 0003 0010 0013 0015 0016 0022 0023 0024 0025 0027 0030 0031 0032 0033 0035 0038 0041 (3 Replies)
Discussion started by: sph90457
3 Replies

2. Shell Programming and Scripting

Reset while loop to loop same file multiple times

Hi, I want to read file multiple times. Right now i am using while loop but that is not working. ex. While read line do while read line2 do echo stmt1 #processing some data based on data., done < file2.txt done < file1.txt # This will have 10... (4 Replies)
Discussion started by: tmalik79
4 Replies

3. Shell Programming and Scripting

Issue with copying files into dir inside for loop

Hi , I'm trying to move/copy the files inside the loop into a directory . I tried the below code and the issue is the data is not copying into the created directory but the files are copying into another file file_path="/home/etc" Last_Day=20130930 mkdir $file_path/ARC_${Last_Day} ... (3 Replies)
Discussion started by: smile689
3 Replies

4. Shell Programming and Scripting

issue while copying file dynamically whith in loop?

I need to copy the log file dynamically and that should run in loop , which means it should pick what ever the latest file is updated in that directory. I am able to display the list and copy to directly but i have no idea on how to pick the dynamically updated files. when i use this code, i... (1 Reply)
Discussion started by: johninweb
1 Replies

5. UNIX for Dummies Questions & Answers

Copying files with spaces in the filename in a for loop

Hi all, I've been tangoing with this one for a couple of days now and I'm still not making any progress. Basically I'm trying to match three numbers in a string from a text file with matching numbers in a jpeg, and then copying the results to another folder. Data looks like this: Model:... (4 Replies)
Discussion started by: faceonline
4 Replies

6. UNIX for Dummies Questions & Answers

Help with searching for a file in a directory and copying the contents of that file in a new file

Hi guys, I am a newbie here :wall: I need a script that can search for a file in a directory and copy the contents of that file in a new file. Please help me. :confused: Thanks in advance~ (6 Replies)
Discussion started by: zel2zel
6 Replies

7. Shell Programming and Scripting

sed command for copying the contents of other file replacing it another file on specifc pattern

We have 2 file XML files - FILE1.XML and FILE2.xml - we need copy the contents of FILE1.XML and replace in FILE2.xml pattern "<assignedAttributeList></assignedAttributeList>" FILE1.XML 1. <itemList> 2. <item type="Manufactured"> 3. <resourceCode>431048</resourceCode> 4. ... (0 Replies)
Discussion started by: balrajg
0 Replies

8. Filesystems, Disks and Memory

Strange difference in file size when copying LARGE file..

Hi, Im trying to take a database backup. one of the files is 26 GB. I am using cp -pr to create a backup copy of the database. after the copying is complete, if i do du -hrs on the folders i saw a difference of 2GB. The weird fact is that the BACKUP folder was 2 GB more than the original one! ... (1 Reply)
Discussion started by: 0ktalmagik
1 Replies

9. Shell Programming and Scripting

copying the csv file into different worksheets of xls file

Hi, I have a script which will generate three csv files. i want to copy the contents of these csv files into a .XLS file but in different worksheets. Can a this be done in the same script? :confused: Can Perl come to my help in coping the csv files into different worksheets of .XLS file ?... (0 Replies)
Discussion started by: nimish
0 Replies

10. UNIX for Dummies Questions & Answers

Copying a file

Can anyone help me with simple problem..... I am newie bee UNIX. I want to copy a file from drive A to /temp directory on drive C. How do i do that.? Thank you (14 Replies)
Discussion started by: jackpotp
14 Replies
Login or Register to Ask a Question