txt file gets messed up during transfer from my Desktop


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers txt file gets messed up during transfer from my Desktop
# 1  
Old 07-14-2011
txt file gets messed up during transfer from my Desktop

Hi,
I am working off of a MacBook Pro OSx 10.5.8.
I have a tab deliminted text file on my desktop that I created in excel. It has 4 columns and 20,000 rows. When I scroll down it in excel, everything lines up perfectly, and is where it is supposed to be. After copying it into my terminal directory however, the text file looks messed up (ie. column/row values switch places, only see partial names in rows), and the script I run (created specifically for these txt files) on it doesnt work. Can anyone tell me why it gets messeed up during the transfer to my terminal, and how to fix it?

This is how I transfer it:
Code:
lrae-macbook-pro:~ lrae$ cd ./Desktop/
lrae-macbook-pro:Desktop lrae$ sftp lrae@ssh.institution.ca
Connecting to ssh.institution.ca...
lrae@ssh.institution.ca's password: 
sftp> cd /home/lrae/file/
sftp> put textfile.txt
Uploading textfile.txt to /home/lrae/file/textfile.txt
textfile.txt     100%  371KB 370.7KB/s   00:01    
sftp>

Any help is greatly apprciated.

Last edited by Scott; 07-15-2011 at 02:19 PM.. Reason: Added code tags
# 2  
Old 07-14-2011
First try the ftp "ascii" command just before issuing the ftp "put" command.
# 3  
Old 07-14-2011
Thank you for your quick response. I am unfamiliar with the ascii command. I tried it though, and got an error of "invalid command".
Was this what you meant for me to do? ...
sftp> ascii put textfile.txt
Invalid command.

sftp> ascii
Invalid command.
# 4  
Old 07-14-2011
sftp always transfers in binary mode, it has no ASCII translation mode. Which is unfortunate since this is one of the rare times when an ASCII translation mode would be useful instead of annoying.

The file isn't actually being mangled. Windows just demands CPM-style text files with CR-LF instead of the plain CR UNIX text files use.

You can translate a file from UNIX cr's into Windows CR-LF's in OSX with
Code:
 awk '{ print $0 "\r" }' < infile > outfile

Usually you can use sed 's/$/\r/' < infile > outfile but OSX's ridiculously old sed doesn't support \r. Some systems also have dos2unix and unix2dos text translation utilities.
# 5  
Old 07-14-2011
So I tried that, and now nothing is being returned. Even when I try to run my script on it, nothing is returned. Can you tell me why this is?
Code:
{xhost}~/home/lrae/file> awk '{ print $0 "\r" }' < filename.txt > filename.txt 
{xhost}~/home/lrae/file> more filename.txt 
{xhost}~/home/lrae/file> cat filename.txt
{xhost}~/home/lrae/file> script.pl filename.txt 
{xhost}~/home/lrae/file>


Last edited by Scott; 07-15-2011 at 02:20 PM.. Reason: Code tags
# 6  
Old 07-14-2011
Because > truncates your file, and the shell does this before awk is even run. You can't redirect into and from the same file simultaneously, it just doesn't work.
# 7  
Old 07-15-2011
Thanks so much Corona688 and Methyl. I have figured out this mess. It turns out that it was a very simple fix. I just had it saved as the wrong type of txt file. I needed to save it as a txt (Windows Formatted Text) file type on the Desktop. That way, it is correctly formatted to be loaded up into my terminal directory.
thanks again
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Ignite-UX INDEX file messed up, how to recreate?

OK, so I just messed myself up. Thinking the /var/opt/ignite/data/INDEX files was static, I manually edited the file and added 2 more OS's to it. During an Install it only showed the first OS (started with 11.31, 3 versions then added a 11.23, and a 11.11 stanza's). The 11.23 and 11.11 never... (2 Replies)
Discussion started by: mrmurdock
2 Replies

2. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

3. Windows & DOS: Issues & Discussions

2 Questions: replace text in txt file, add text to end of txt file

so... Lets assume I have a text file. The text file contains multiple "#" symbols. I want to replace all thos "#"s with a STRING using DOS/Batch I want to add a certain TEXT to the end of each line. How can I do this WITHOUT aid of sed, grep or anything linux related ? (1 Reply)
Discussion started by: pasc
1 Replies

4. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

5. Windows & DOS: Issues & Discussions

Transfer of zipped folder from windows desktop to UNIX server

Hi all, I'm a newbie to unix. My requirement is to create an automation script which will transfer a zipped folder from my/remote desktop to an unix server. Tools lik WinSCP shouldnt be used. No manual moving. I use putty to connect to server. I couldnt find any help on this topic. Should i use... (3 Replies)
Discussion started by: sherin22
3 Replies

6. Shell Programming and Scripting

awk append fileA.txt to growing file B.txt

This is appending a column. My question is fairly simple. I have a program generating data in a form like so: 1 20 2 22 3 23 4 12 5 43 For ever iteration I'm generating this data. I have the basic idea with cut -f 2 fileA.txt | paste -d >> FileB.txt ???? I want FileB.txt to grow, and... (4 Replies)
Discussion started by: theawknewbie
4 Replies

7. UNIX for Dummies Questions & Answers

Can't loging because .basrc file messed up

Dear Friends, I have messed up with my .bashrc file (something I have deleted) and now i can't login back to system.. any Idea.. I can do login with other login and password.. but I dont have root password because of security reason... If I ask root then It will take about 4 -5 days to go... (4 Replies)
Discussion started by: umeshjaviya
4 Replies

8. Shell Programming and Scripting

command to list .txt and .TXT file

Hi expersts, in my directory i have *.txt and *.TXT and *.TXT.log, *.txt.log I want list only .txt and .TXT files in one command... how to ?? //purple (1 Reply)
Discussion started by: thepurple
1 Replies

9. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies

10. UNIX for Dummies Questions & Answers

Binary txt file received when i use uuencode to send txt file as attachment

Hi, I have already read a lot of posts on sending attachments in unix...but none of them were of help for my problem...so here goes.. i wanna attach a text file and send to a mail id..used the following code : uuencode "$File1" "$File1" ;|mail -s "$Mail_sub" abc@abc.com it works... (2 Replies)
Discussion started by: ash22
2 Replies
Login or Register to Ask a Question