UNIX commands for a script that I need


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers UNIX commands for a script that I need
# 1  
Old 07-14-2012
UNIX commands for a script that I need

Hello. I need help trying to create a script in UNIX to do the following steps. I don't know which commands to input to achieve this.


1. In a directory tree, I want to duplicate all .txt files into the same directory, so 2 of each file exists in each directory where there is a .txt file

In the newly created files, I need to:
2. Change the extension to .dat
3. Remove the first 2 lines of text
4. Copy the first 8 lines from an outside, static file, and paste them into the first 8 lines of the newly created files


I don't know if the steps above are the right way to approach what I want to accomplish so I would appreciate any insight and help you all have to offer.

Thanks.
# 2  
Old 07-14-2012
Is this school work?
# 3  
Old 07-14-2012
Im a natural science graduate student and I'm looking for an easy way to format files before I start a project.
Rather than doing this manually hundreds of times with what I have now, and several hundred times after I begin, I figured a script would be the better approach.
Needless to say, programming isn't my forte.


I came up with this so far, but it only works in a directory. I want this to be able to work in every folder in the directory root I choose. (such as root ls shows folders A B and C, and if the .xyz files are in A B and C, i can run the command from the root and have it work in folders A B and C)

"
Code:
find *.xyz | sed -e "s/^\(.*\)\.xyz/\1\.xyz \1\.wip/g" | xargs -n 2 mv -f 
sed -i '1d;2d' *.wip 
sed :1,8y ~/Test/source/SourceFile.dat > *.wip 
find *.wip | sed -e "s/^\(.*\)\.wip/\1\.wip \1\.dat/g" | xargs -n 2 mv -f

"

Line 1: rename .xyz file to .wip
Line 2: delete first 2 lines of .wip
Line 3: add 8 lines from Sourcefile into .wip
Line 4: rename .wip to .dat

I'm currently testing through inputting the codes 1 line at a time since I don't know how to write a script just yet.

Last edited by methyl; 07-14-2012 at 05:10 PM.. Reason: please use code tags
# 4  
Old 07-14-2012
What Operating System and version is this and what Shell do you use?
# 5  
Old 07-14-2012
I believe the shell im using is Teraterm secure shell extension (ttssh) v1.5.4

and linux (woops Smilie)

I used the uname -a command to get the following info.

Linux n1 2.6.18-194.3.1.el5 #1 SMP
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create a UNIX script file with multiple commands

Hi Good morning all, I want to create script file with multiple commands. For ex: pmrep connect is one of the command to connect to repository. pmrep objectexport is another command to export objects to a file. These commands should run sequentially.But when i try to execute this, the first... (4 Replies)
Discussion started by: SekhaReddy
4 Replies

2. Shell Programming and Scripting

Windows Batch script for Unix commands

I wish to create a folder on a unix server B from my windows box using windows batch script. Below is my windows batch script. @ ECHO OFF ::Enter your Directory name: echo Enter your Directory name: set /p mydir= plink user1@ServerA mkdir %mydir% At plink command i get logged... (7 Replies)
Discussion started by: mohtashims
7 Replies

3. Shell Programming and Scripting

Need help embedding Unix commands in a shell script

Hi Folks, I have a text file which may or may not have any data. I would like to email the file, via a Korn shell script, if the file is not empty. I am fiddling around with the wc -l command, but no luck so far. The pseudo code is as follows count=`wc -l test.txt` if cat test.txt... (4 Replies)
Discussion started by: rogers42
4 Replies

4. Web Development

cgi script and external UNIX commands (like swadm)

Hi, I am trying to implement a server monitoring dashboard using cgi scripting. I am planning to run the necessary unix scripts from the web page using cgi. This method works fine for standard unix commands but I am unable to run some external unix commands (like swadm show_processes, swadm... (9 Replies)
Discussion started by: jofinjoseph
9 Replies

5. UNIX for Dummies Questions & Answers

commands to execute unix script

commands to execute unix script (1 Reply)
Discussion started by: sunilamarnadh
1 Replies

6. Shell Programming and Scripting

Running unix commands in a perl script

Executing two unix commads via perl script one after another e.g: make clean bsub -i -q short make have tried using exec but the second command doesnt executes (1 Reply)
Discussion started by: rajroshan
1 Replies

7. Shell Programming and Scripting

Running multiple unix commands in a single script

Hi, I would like to write a script with include more than 6 unix commands. my script like below: echo " script started" ls -ld bdf | grep "rama" tail -10 log.txt ... .. ... now, i want to run above unix commands one by one. example: first the ls -ld command will be... (3 Replies)
Discussion started by: koti_rama
3 Replies

8. Shell Programming and Scripting

How to write a script by using unix commands to down any server

Hi, I need to do frequently server down and up. Every time i am using nearly 5 to 6 commands to down and agin i am using the commands to up. Can anybody help me to write a script to down and up. which i can use once on unix platform it can down later it can up the server. (1 Reply)
Discussion started by: sreerao
1 Replies

9. UNIX for Dummies Questions & Answers

Unix commands in perl script

I am totally new to unix commands but I need to understand the following command which is a part of a perl script..what does this mean? myPwd = $(pwd) myTracker = $myPwd/myTracker.out exec > $myTracker 2>&1 (1 Reply)
Discussion started by: athri
1 Replies

10. Shell Programming and Scripting

Doubt on Executing unix commands in script

How can I execute the unix command "cd - Change directory" command, so that my command prompt should be reflected for that change. Example : Now you are in your home directory i.e /home/naresh and you have some sub directory called unixinfo in your home directory. i want to write a script,so... (2 Replies)
Discussion started by: Naresh Kumar
2 Replies
Login or Register to Ask a Question