.bat or .pl script help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting .bat or .pl script help
# 1  
Old 11-22-2010
Debian .bat or .pl script help

hi
I need to rediret an content of one file and append it to another file. I need it in .bat script. I tried this,

first.txt
I love to write script

type first.txt >> out.txt
type first.txt >> out.txt

out.txt
I love to write scriptI love to write script

you see the second append go in the same line.I need to print the second append to go in the next line.Like this

I love to write script
I love to write script

Can oneone help me.

also let me know the perl coding for this.

thanks...
Gopal
# 2  
Old 11-22-2010
Quote:
Originally Posted by ilugopal
I need it in .bat script.
I'm sad to have to say this, but this sounds like homework. Homework is forbidden here, as there is a special forum for it, with special rules in place. Furthermore, this seems to deal with a DOS/Windows problem for which there is also another forum.

As you have undertaken a serious effort to solve your problem yourself and shown it i will make an exception to the rule ad answer, but PLEASE DO NOT TAKE THIS AS AN INVITATION to further stretch the rules.

Code:
first.txt 
I love to write script

Code:
type first.txt >> out.txt
type first.txt >> out.txt

out.txt
Code:
I love to write scriptI love to write script

Quote:
Originally Posted by ilugopal
you see the second append go in the same line.I need to print the second append to go in the next line.
The reason for this behavior is not your script but your input file: you omitted the last linefeed after the end-of-file marker. Open your file "first.txt", got to the end of the line and press <ENTER>, then save the file. You will notice that your script will now work.

Here is some explanation: a file consists not only of readable ("printable" - which means also printable to the screen) characters and blanks, but also special characters used to transport some steering information. One of these special characters (or character combinations) is the "EOF", the "end-of-file"-marker, which has to be at the end of every file. In Unix this is a "^D" (CTRL-D) character, in DOS, Windows (and, historically, in CP/M) this is a "^Z" (CTRL-Z). See this reference for more information. The same is the case for the end of a line: Your computer has to somehow discern between

Code:
one linesecond line

and
Code:
one line
second line

and this is done by inserting a special character which does exactly that. In DOS/Windows this is in fact a character combination, "CR/LF" ("Carriage Return", followed by a "Line Feed") with the hex codes "0D 0A". In Unix this is simply a "Line feed" character (hex "0A").

Btw: This difference is why there is a "binary" and a "text" mode in ftp: "text mode" would mean to translate "0D0A" to "0A" when transferring a file from a Unix system to/from a DOS system, "binary mode" means to not do this translation.

See this wikipedia article for more information about "Newline".

However, if you would display your file "first.txt" including these non-printable characters (use a hex-editor or "od" on a Unix-system) you would see:

Code:
f i r s t   l i n e ^Z

When you "type" that two time into another file, the following happens: first the EOF character is removed, then the remainder is copied to the empty output file, then a EOF character is appended to the output. Then the second file is read, the EOF character of it is removed, text is appended to the output file and an EOF character is appended again. By now you have what you got with your script.

If the file would have contained an EOL character it would now contain "text<EOL>text<EOL><EOF>" and this would look like your desired output.

I hope this helps to understand.

bakunin

-closed-
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Convert .sh to .bat please

Can someone translate this code to .bat for me? I have no clue. #!/bin/sh WAS_HOME="/opt/websphere/appserver/profiles/AppSrv01" WAS_APP_SERVER="server1" WAS_PROFILE_NAME="AppSrv01" echo "Stopping App Server" "${WAS_HOME}/bin/stopServer.sh" -profileName $WAS_PROFILE_NAME $WAS_APP_SERVER... (1 Reply)
Discussion started by: Blogger11
1 Replies

2. Shell Programming and Scripting

BAT to SH help

First off, let me apologize if I'm posting this in the wrong place! I am a newbie to this forum, to shell scripting and to Linux so please bare with me. I created a script on the windows environment that makes a call to a java application and extracts a return value from the java app. It... (7 Replies)
Discussion started by: arod291
7 Replies

3. Shell Programming and Scripting

Need help with bat file!!!

I need to put/get files from Windows machine to Unix machine and vice-versa. I wrote a text file "ftp1.txt" as below. naga naga06 cd /root/Naga prom off get time.unl bye I wrote another bat file "ftp.bat" as below. ftp -n -s:C:\Users\Naga\Desktop\ftp1.txt IP_ADDRESS but... (2 Replies)
Discussion started by: Naga06
2 Replies

4. Shell Programming and Scripting

bat to shell

I have serverfiles of same game. and there are bat files. I wont to run this on debian. The files are difficult, eg :######################################################################## :# File name: server_start.bat :# Edited Last By: Mike Gleaves (ric) :# V 1.0 1-10-2008 :# Comment:... (5 Replies)
Discussion started by: Qentinios
5 Replies

5. Windows & DOS: Issues & Discussions

Executing .bat file

Hi , I have a bat file on windows machine ,I need to excute it from my local unix machine using sambe utility.Is there any comman to execute the .bat file remotely. Using samba utility i can post files to and fro from windows to unix but i don't comman to exute the .bat file. can any one... (2 Replies)
Discussion started by: Raamc
2 Replies

6. Windows & DOS: Issues & Discussions

.bat script help

hi I need to rediret an content of one file and append it to another file. I need it in .bat script. I tried this, first.txt I love to write script type first.txt >> out.txt type first.txt >> out.txt out.txt I love to write scriptI love to write script you see the... (6 Replies)
Discussion started by: ilugopal
6 Replies

7. Windows & DOS: Issues & Discussions

Calling a .bat file using Korn script

Hi all, I am a very new user for korn scripting and in a process of learning. i have a .bat file that calls a .vbs file which calls a macro used to convert an excel spread sheet to .csv file... Now i want to automate this process. I want to call this bat file using a korn script or a korn... (6 Replies)
Discussion started by: bhagya2340
6 Replies

8. Windows & DOS: Issues & Discussions

one question for .bat file

Hi! I'm very sorry for such simple and silly question but I cannot answer it by myself. Can you please help me? In .bat file I should run the C program which is in other directory, and the input configuration file is in this directory too. This dir name is in dirRun variable. The... (3 Replies)
Discussion started by: Anta
3 Replies

9. Shell Programming and Scripting

Run shell script from .bat file

hi how can I execute a shell script on unix server from a .bat file of windows desktop?? Regards. (3 Replies)
Discussion started by: Chaitrali
3 Replies

10. UNIX for Dummies Questions & Answers

Can Unix (Solaris) execute a dos .bat script?

I did a search and found lots of questions/comments about how a dos script could execute Unix but not the other way round. If it's possible, I'd like the link to a post/site that would show me the way. Thanks. (4 Replies)
Discussion started by: BCarlson
4 Replies
Login or Register to Ask a Question