Help required for creating script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help required for creating script.
# 1  
Old 03-20-2011
Help required for creating script.

I want to create a shell script which should be doing following things .. i have the commands but do not know how to tie them up together.

1. . Go to a pre-defined directory and look for a specific pattern txt files like abc12* and select the latest file with abc12*

Code:
ls |awk '{if($NF ~ "fin") {print $NF}}' | sort -r | sed -ne '1p

2. If file exist then put it for further processing in another command

Code:
k="$( cat $i | cut -d"|" -f49 )"

3. Then save the different files with name of o/p you get in the above command

Code:
"${i}" >> "/tmp/outputs/${k}"


4. Then move the file to some different folder and clean up the current directory.

Code:
rm -rf $i

5. Script should exit after processing and removing the file. And if it runs again and didn't find the file then also it should exit.


Any help is appreciated.
# 2  
Old 03-20-2011
Quote:
Originally Posted by fugitive
1. . Go to a pre-defined directory and look for a specific pattern txt files like abc12* and select the latest file with abc12*
What do you understand by "latest"


Quote:
Originally Posted by fugitive
Code:
ls |awk '{if($NF ~ "fin") {print $NF}}' | sort -r | sed -ne '1p

What is the output of ls ? Do you have space in filename? Maybe a ls -r *fin* | head -1 can solve your problem.

Quote:
Originally Posted by fugitive
2. If file exist then put it for further processing in another command


Code:
k="$( cat $i | cut -d"|" -f49 )"

You don't need the cat Smilie k="$( cut -d"|" -f49 $i )"

Quote:
Originally Posted by fugitive
Code:
"${i}" >> "/tmp/outputs/${k}"

Where you declare ${i} ? Try to post your script.


Quote:
Originally Posted by fugitive
4. Then move the file to some different folder and clean up the current directory.

Code:
rm -rf $i

Do you need a temporary file?
# 3  
Old 03-20-2011
1. yep u were right
Code:
 ls -r *fin* | head -1

can help me as its giving me the same output as the other command.

Code:
 ls |awk '{if($NF ~ "fin") {print $NF}}' | sort -r | sed -ne '1p


2. and i used cat when i was running the individual command from the user prompt and wanted to see the o/p


3. i want following code in such a way that " i " should be used used from
the result of above command.


Code:
while read i; do
    k="$( echo $i | cut -d"|" -f29 )"
    echo "${i}" >> "/tmp/outputs/${k}"
done < fin.txt


4. Nope i do not need temporary file. Its just that these txt (flat) files are created by a program and then one file has to be selected out of other files which is most recent. And then that file has to be removed once processing is done on that file.
# 4  
Old 03-20-2011
What about:
Code:
while read i; do
    echo "${i}" >> "/tmp/outputs/$(cut -d"|" -f29 $i)"
done < fin.txt

# 5  
Old 03-20-2011
nope that didn;t work i do not want to change


Code:
while read i; do
    k="$( echo $i | cut -d"|" -f29 )"
    echo "${i}" >> "/tmp/outputs/${k}"
done < fin.txt


I just want to tie it up with other things ..

1. lookout for most recent file out of bunch of files and then use the output (file name ) for $i

2. run the code sort the files according to it and then move the file to some other location.

Last edited by fugitive; 03-21-2011 at 03:37 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in creating a file in required format form another existing file

I have a text file with contents like this: a,b,c, d~e,f,g,h~i,j ,k,l,m~n,o,p,q~ I need to convert this file into this format unix shell script commands: a,b,c,d~ e,f,g,h~ i,j,k,l,m~ n,o,p,q~ as you may have noticed, I need to retain the ~ signs at the end. Any help is greatly... (3 Replies)
Discussion started by: harsha1238
3 Replies

2. UNIX for Dummies Questions & Answers

Perl Script:how to find how many parameters are required to run the script

How to find how many parameters are required to run a Perl script? (1 Reply)
Discussion started by: Lakshman_Gupta
1 Replies

3. UNIX for Dummies Questions & Answers

Creating a File system with required permissions for all DIR's created in

Hello All, I am application admin. I need to clear all the temporary files cleared by the applications. I need help/suggestion that is there any way to create a file system such that every Dir created in by any user will have 775 permissions. So, that i can simply clear the temporary file which... (6 Replies)
Discussion started by: firestar
6 Replies

4. Solaris

Creating A Solaris Zone - Unable to install - Are network settings required?

Hi i have created a solaris zone but have not yet connected any network cables for this new zone, can i set the zone up without running the command 'add net' and not adding an ip or physical interface? i tried to add dummy internet settings and get this zonecfg:coddr> add net... (4 Replies)
Discussion started by: newbiesolaris10
4 Replies

5. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

6. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

7. UNIX for Advanced & Expert Users

Why root permissions required for creating of RAW Socket

To create RAW socket in Unix/Linux why should one have root permissions? Any other work around to create raw sockets in Unix/Linux using a normal login id? Since I don't have super user credentials and I want to create RAW sockets. Let me know if you are aware of any work around. (3 Replies)
Discussion started by: anilgurwara
3 Replies

8. Shell Programming and Scripting

Help required in creating a shell script that filters the unwanted pattern

Kindly help, Suppose i am having a file that has got the following contents. Is there any way (eg. sed command) to remove the (*) (*any number) pattern. se.bas tulf.h (1) tuna.c (1) tunsim.c (1) tus.cpp (1) vp.c (1) vp.h (1) vpi. (1) (1 Reply)
Discussion started by: frozensmilz
1 Replies

9. Shell Programming and Scripting

plz help me by creating required shell script

Dear all I am new to shell script. And this is my first post to this site as well as this forum. I would like to tell this forum that I require shell script, which is regarding transfers of files from a specific directory in a server A to server B on a specific directory through sftp command.... (5 Replies)
Discussion started by: girish.batra
5 Replies

10. Shell Programming and Scripting

Script help required!

Hi there, i am trying to create a script that checks for the existence of users on the system, if they exist then their details should print on the screen with a message that the id is in use. I am having a bit of trouble with it. Any ideas? Cheers Kev! (8 Replies)
Discussion started by: kev112
8 Replies
Login or Register to Ask a Question