function for variable files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting function for variable files
# 1  
Old 11-12-2011
Power function for variable files

hi all
this is my function

Code:
#! /bin/sh
awk '/ Type/ { print "m;" $4 } /IDf/ {print $3 } /IuSac/ { print $3 } /IuSac/ { print $1 }' / IBM.txt |tr '\n' ';'| perl -pi -e 's/;m//g'|cut -d ";" -f 2-5 ' >> 2m

1) i wanna make it to save output of awk in a file named by date in order not to overwrite nor put it on same file ( big size problem ) not 2m

2) im working in IBM.txt file in /company/IBM.txt this directory has IBM1.txt
IBM2.txt and so on ......
so i wanna make file field in awk to be variable for example to get *.txt to get anyfile named ,,,,, . txt in company directory





thanks alot

Last edited by teefa; 11-13-2011 at 08:48 AM.. Reason: wrong formate & no reply
# 2  
Old 11-14-2011
Teefa,

Can you provide some sample input, desired output, and what you think your 'function' is trying to do?
# 3  
Old 11-14-2011
Code:
the awk is getting the fields after print in the lines containing the /  / word 
tr here to make them in records
perl here as identifier 
cut to get specific fields

Code:
1-here the script will be saved in a file named 2m ................... i wanna it to be (DD/MM)/m   for example to save file by name of its date every day save in a new file

Code:
2-here infile name IBM.txt in directory company 
its path is /company/IBM.txt 
in this directory there is alot of txt files (IBM1.txt , IBM2.txt , IBM3.txt ,.....so on )
i wanna take all files .txt in a directory and make this script run for it to be saved in output file

At the end i wanna say whatever any awk script can be put up
Code:
awk ' /type/ { print $0} ' /IBM.txt >> 2m 

i wanna output named by date every day 
awk ................/ *.txt  in the directory mentioned

thanks alot Smilie Smilie Smilie Smilie
# 4  
Old 11-15-2011
And from what I can tell, you are using four programs to do the work of just one - awk or perl. Can you please provide a sample of the input and an example of the desired output, so I can at least figure out if what you wrote does what you intend.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass variable from one function to another function?

updateEnvironmentField() { linewithoutquotes=`echo $LINE | tr -d '"'` b() } I want to pass variable named $linewithoutquotes to another method called b(), which is called from updateEnvironmentField() method. How to do the above requirement with shell script (1 Reply)
Discussion started by: pottic
1 Replies

2. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

3. Shell Programming and Scripting

Passing variable value in a function to be used by another function

Hello All, I would like to ask help from you on how to pass variable value from a function that has been called inside the function. I have created below and put the variables in " ". Is there another way I can do this? Thank you in advance. readtasklist() { while read -r mod ver... (1 Reply)
Discussion started by: aderamos12
1 Replies

4. Shell Programming and Scripting

How to pass a function with a variable parameter into another variable?

Hello again :) Am currently trying to write a function which will delete a record from a file. The code currently looks as such: function deleteRecord() { clear read -p "Please enter the ID of the record you wish to remove: " strID ... (2 Replies)
Discussion started by: U_C_Dispatj
2 Replies

5. UNIX for Dummies Questions & Answers

function not see variable in script

Hi Forum Can anyone tell me whats wrong with my script. What i want to do read in values from a input file using a while loop then taking that input from the file into a function that i created. Every time i execute the script it goes through the while loop but the function doesn't see the... (10 Replies)
Discussion started by: ShinTec
10 Replies

6. Shell Programming and Scripting

Variable value not retaining outside function

Hi All, As per my understanding, value of variable is retained outside function. But the value of array myarrayDriver is not retained outside function. Could you please tell the reason for the same.. code: readingConfigFile() { search_keyword="$1" i=0 for pointer in $(cat... (7 Replies)
Discussion started by: ajincoep
7 Replies

7. UNIX for Dummies Questions & Answers

Calling a function through a variable

Hey folks, I'm pretty new to unix programming. I was trying to get something to work but it's not doing what I expected. #!/bin/ksh . ./functions.sh STRING=function_1 FUNCTION="$STRING" RETURN=eval $FUNCTION echo "value of $FUNCTION function is: $RETURN" All i'm... (5 Replies)
Discussion started by: Irrational
5 Replies

8. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

9. UNIX for Dummies Questions & Answers

passing a variable inside a variable to a function

I would like to know how to pass a variable inside a variable to a function. sample code below -------------- for x in 1 9 do check_null $C$x ##call function to check if the value is null if then echo "line number:$var_cnt,... (2 Replies)
Discussion started by: KingVikram
2 Replies

10. UNIX for Dummies Questions & Answers

passing variable to function

Hi, I am trying to sum up numbered columns and in order to tidy up the program I have wrote a function to do the adding of some numbers. I have a problem though with passing a variable to the function in the UNIX bash shell. The function only gives the first number in the variable list and does... (4 Replies)
Discussion started by: Knotty
4 Replies
Login or Register to Ask a Question