Pointers on writing a unix script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pointers on writing a unix script
# 1  
Old 10-06-2009
Pointers on writing a unix script

Hi All,

I am writing a unix shell script. I have a file called Results.txt which stores 4 fields separated by pipe. i.e. a pipe delimited file. I want to loop through each record of this file and store each of these 4 fields into variables. I have read can be done through awk but I have never worked on unix. Any immediate help would be highly appreciated. Please help.

Regards,
Shweta
# 2  
Old 10-06-2009
What are you trying to do? What is the input? What is the expected output? What have you done so far?
# 3  
Old 10-06-2009
I have a file Results.txt
format as below
FEED_ID| FEED_DESCRIPTION|FILE NAMES|NUMBER OF FILES
374|Jane - Sensitivities (EUI8)|SYCEUI8_yyyyMMdd_RISK.CSV, SYCEUI8_yyyyMMdd_PCA.CSV, RMMEUI8_yyyyMMdd_ORIGINAL_Details.CSV|3
472|Jane - Sensitivities (PRP2)|SYCPRP2_yyyyMMdd_RISK.CSV, SYCPRP2_yyyyMMdd_PCA.CSV, RMMPRP2_yyyyMMdd_ORIGINAL_Details.CSV|3
.

I want to loop through each record of this file and store each field as variables so that I can use them to pass as parameters to further part of my script

I want to create such a loop that I can pass each feild of this Results.txt as a parameter to an xml filw which i am using in next part of my script.

Please help
# 4  
Old 10-06-2009
A simple example that will reverse the order of the fields (pure shell):
Code:
while IFS='|' read ID DESC FILENAME FILENUM
do
    echo $FILENUM"|"$FILENAME"|"$DESC"|"$ID
done < Results.txt

# 5  
Old 10-06-2009
Hi there

Thanks for the reply.
Suppose I have to pass the FEED_ID as a paramtere to the below xml as a value for JOBNAME how do I go about it. This is very urgent for me. Please advise.

<DEFJOB><JOB APR="1" AUG="1" DEC="1" FEB="1" JAN="1" JUL="1" JUN="1" MAR="1" MAY="1" NOV="1" OCT="1" SEP="1" GROUP="RATES_FILEWATCH" OWNER="rdsprod" RETRO="0" SHIFT="IGNOREJOB" SYSDB="0" AUTHOR="drutter" CYCLIC="0" NODEID="rds" TIMETO="&gt;" CMDLINE="/app/ControlMagent6.2/prod/PLNSHCTM03/exe/ctmfw /app/data/rds/PLNMARS4/todo/SYCLEX_%%$ODATE._RISK.CSV CREATE 0 30 200 3 600 Y " CONFIRM="0" JOBNAME="RDS1084001" MAXDAYS="0" MAXRUNS="0" MAXWAIT="5" MEMLIB="" MEMNAME="" AUTOARCH="0" CRITICAL="0" INTERVAL="00030M" MAXRERUN="0" SHIFTNUM="+00" TASKTYPE="Command" TIMEFROM="2150" WEEKDAYS="1,2,3,4,5 *" DATACENTER="PLNSHCTM03" IND_CYCLIC="START" TABLE_NAME="RDS_CREDITPRODUCTS" ADJUST_COND="N" APPLICATION="RDS" DAYS_AND_OR="AND" DESCRIPTION="Filewatch Jane LEX Risk" MULTY_AGENT="N" CHANGE_USERID="drutter" CREATION_DATE="20060517" CREATION_TIME="110744" CREATION_USER="drutter">
<ON CODE="*" STMT="*">
<DOSYSOUT PAR="/app/log/rds/%%JOBNAME..%%DATE.%%TIME" OPTION="Copy"/>
</ON>
<OUTCOND NAME="RDS-RDS1084001D-OK" ODATE="ODAT" SIGN="ADD"/><SHOUT WHEN="EXECTIME" TIME="" DEST="RDS_SUPPORT" URGENCY="V" MESSAGE="%%JOBNAME OVERRUNNING REVIEW DOC"/></JOB>
# 6  
Old 10-06-2009
Hi,

The following snippet may help you. Lets say you have a file OrdersPerSecond.txt with three columns and a few rows and you need to store each column field into a variable which then can be inserted in a tab formatted excel.
You perhaps could use the following simple loop.

Code:
 
#!/bin/ksh

cat $HOME/OrdersPerSecond.txt | while read line
do
FEILD1=`echo $line |awk '{print $1}'`
FEILD2=`echo $line |awk '{print $2}'`
FEILD3=`echo $line |awk '{print $3}'`
 
echo "$FEILD1 \t $FEILD2 \t $FEILD3" >> OrdersPerSecond.xls
done

Cheers
Sumedha

Last edited by Sumedha Sobti; 10-06-2009 at 08:39 AM..
# 7  
Old 10-06-2009
Thanks Sumedha

Can you also point out how to pass the values as variables to the xml I gave above
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

i writing a unix script but i want to out put a file and append on it.

i have an existing script that is used to send an e-mail containing the alrams that appear on the server. But i need to create a daily log file containing all the alarms that was send that day. i tired to add at the and of the script a command, echo command but for some reason the file was... (1 Reply)
Discussion started by: ashraf_victory
1 Replies

2. UNIX for Dummies Questions & Answers

Teaching myself Unix - Need websites and other pointers

Hi, I am new to Unix. I've started with a book "Unix for Dummies". Please help, any websites with extensive amount of practice exercises are needed. I need to practice! Also I would appreciate any books that are good for beginners. Thanks to all! (1 Reply)
Discussion started by: zamcruiser
1 Replies

3. UNIX for Dummies Questions & Answers

New guy needing help writing a Unix Script

I'm very new with Unix and and am needing assistance in writing a Unix script that will uncompress a dated file then rename it. The script will also need to remove several old files that have a similar naming. The directory that the files reside in is call achdirdep the file that I need uncompress... (1 Reply)
Discussion started by: mlx707
1 Replies

4. Shell Programming and Scripting

Writing Unix script to accept arguments

Hi, This may be answered elsewhere but I wasn't entirely sure of the wording I should use to search so here we go with an attempt: I wish to make a script that will allow commands to be passed to it such as: <command> -oOPTIONS -aANOTHER -pRINT etc However I don't really know the... (3 Replies)
Discussion started by: stuaz
3 Replies

5. Shell Programming and Scripting

Need help in writing script for finding files in the unix machine?

I would like to find whether a file exists in the UNIX machine. That i can check using if ;then echo "exists" echo " `cat $file` " else echo "invalid file" fi. and i can find out using : find / -name "filename" . But it i have wanted to search in all directories. How to get... (3 Replies)
Discussion started by: rparsa001
3 Replies

6. Shell Programming and Scripting

need help writing this unix script

Create an executable script file called "newname" that will perform the followings: 1. Rename a file upon the user's request. If the file exists, prompt the user for confirmation before renaming the file. The screen should prompt the user for a. "Name of file you want to rename." Use the "\c"... (7 Replies)
Discussion started by: wiggles
7 Replies

7. Shell Programming and Scripting

help writing this unix script

I am working on writing scripts. Here is a script I need help with. I have also wrote what I think it is. I would really appreciate any help that I can get. Create an executable script file called "newname" that will perform the followings: 1. Rename a file upon the user's request. If the... (2 Replies)
Discussion started by: wiggles
2 Replies

8. UNIX for Dummies Questions & Answers

Perl Unix Script Writing

Hi Folks, I posted a few days ago, thanks for the responses. My original question was for renaming files of sort 3p2325294.dgn in a directory containing multiple files. I need to drop the first 2 characters and the last in a unix script using Perl. How does it differ from using the Unix... (1 Reply)
Discussion started by: Dinkster
1 Replies

9. Programming

relative pointers on Unix

Hi all: We're porting lot of C code from Windows to Unix. In Windows we're using relative pointers (with the _based keyword) to access some structures placed on shared memory. We would need something like the Microsoft's _based keyword for unix. Does something similar exist in Unix? If not, is... (3 Replies)
Discussion started by: rahul_verma
3 Replies

10. Shell Programming and Scripting

Need help in writing a unix script

OS: Solaris Shell : KSH Please help me in writing a script that captures a error message from a log file ( which updates continiously ) and send an email alert as soon as the systems throws a error message into that log. i.e With out monitoring the log Thanks in advance.. (1 Reply)
Discussion started by: pray44u
1 Replies
Login or Register to Ask a Question