![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| OS X (Apple) OS X is a line of Unix-based graphical operating systems developed, marketed, and sold by Apple. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Redirection not working as expected | findprakash | UNIX for Dummies Questions & Answers | 1 | 07-15-2008 04:06 AM |
| #/usr/bin/csh -f not working as expected? | effigy | Shell Programming and Scripting | 4 | 06-05-2006 05:00 PM |
| Find command not working as expected | mpflug | UNIX for Dummies Questions & Answers | 2 | 02-09-2006 08:32 PM |
| ls not working as expected within ksh | GNMIKE | Shell Programming and Scripting | 10 | 07-07-2005 07:53 AM |
| which not working as expected | osee | Shell Programming and Scripting | 2 | 09-07-2004 11:37 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Cat command not working as expected
I've been trying to figure this out since last night, and I'm just stumped. The last time I did any shell scripting was 8 years ago on a Unix box, and it was never my strong suit. I'm on a Mac running Leopard now. Here's my dilemma - hopefully someone can point me in the right direction.
I'm trying to process product datafeeds - plain text, thousands of lines, pipe delimited. My shell script prepares a directory, then downloads via curl a zip file. It unzips the file. It greps out lines containing a keyword and redirects into a new file. I use a perl command to find/replace my ID number in the file. Everything I've described works perfectly - but the next step is the problem. I need to add the field names to the top of the file so I can put the file into WebMerge and process it. The field names are on a single line in a separate text file called FirstLine.txt. I use this: cat FirstLine.txt kids.txt > readyToProcess.txt to combine the files. What I expect is that if FirstLine.txt contains foo and kids.txt contains bar, then readyToProcess.txt should contain foo(new line)bar. What I'm getting instead is that the file contains foobar. Is there a situation where the cat command wouldn't put the contents of the first file on a new line? Thanks for any help you can offer - I'm rather stuck until I figure this out! ~Daniel |
|
||||
|
Ah-ha. Okay, I think I'm onto something... I spent some time researching the line terminator thing (have been since last night actually) but everything I came up with kept telling me that my line terminator was Unix-style. Just now though, I punched file FirstLine.txt into Terminal and it came back with FirstLine.txt: ASCII text, with no line terminators.
Great. So... how do I insert a line terminator? I found many, many resources that talk about the tr command and changing \r to \n but nothing in the way of adding a line terminator where none exists. |
|
||||
|
I was hoping you wouldn't say that
See, I figured there must be some trick or something, because when I simply add a new line like that (by opening in TextWrangler and hitting Enter at the end of the line), my output gets... weird. This is a short example of what it was doing when I first posted. FirstLine.txt: Quote:
Quote:
Quote:
Quote:
|
|
||||
|
Also - I ran printf "\n" >> FirstLine.txt and the result was the same as when I open the file in TextWrangler and add the new line manually. Oddly, when I cleared that new line and ran printf "\r" >> FirstLine.txt the output is almost correct. I get this:
Quote:
![]() |
|
|||||
|
That's strange. You could try to edit it with VIm, adding an empty line and deleting it again, as it usually adds the appropriate EOL when saving a file. Also, if you enter ':set list', you'll see any special characters (eg. $ for EOL, ^I for tab, ...)
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|