Parsing files depending on the content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing files depending on the content
# 1  
Old 08-29-2013
Parsing files depending on the content

I am trying to parse files kkapjil kkpcjil kkexjil ...which have autosys job names. The objective is to parse each file...do an autorep -j <job name > -q and write it as output with a line for condition at the end of the each job. The problem I am facing is with the box jobs...as autorep -j <box name> -q would also list the child jobs and the condition would listed at the end of the last child job.
Code:
#*************************************
#more kkapjil
#+ more kkapjil
#testing_box.ttap0009
#testing_box.ttapbpo
#*************************************
#more kktcjil_cmd
#+ more kktcjil_cmd
##testing_cmd.tttc0001_1_ae_gprd8
##testing_cmd.tttc0125_ae
#testing_cmd.tttc0113_ae
#testing_cmd.tttc0118_ae
#testing_cmd.tttc0110_ae
#testing_cmd.tttc0111_ae
#testing_cmd.tttc0112_ae
#testing_cmd.tttc0119_ae
#testing_cmd.tttc0128_ae
#testing_cmd.tttc0120_ae
#testing_cmd.tttc0104_rb
#testing_cmd.tttc0109_sqr_4
#testing_cmd.tttc0126_ae
#testing_cmd.tttc0114_ae
#testing_cmd.tttc0117_ae
#testing_cmd.tttc0115_ae
#testing_cmd.tttc0116_ae
#testing_cmd.tttc0100_ae
#testing_cmd.tttc0121_ae
#testing_cmd.tttc0128_ae_2
#testing_cmd.tttc0120_ae_2
#testing_cmd.tttc0109_sqr_3
#testing_cmd.tttc0129_ae
#***************************************************
 
#set -A files kkapjil kkpcjil kkexjil kkgljil kkpojil kkpajil kktcjil kktrjil restjil kkapjil_cmd kkpcjil_cmd kkexjil_cmd 
#kkgljil_cmd kkpojil_cmd kkpajil_cmd kktcjil_cmd kktrjil_cmd restjil_cmd
set -A files kktcjil_cmd
rm kk*jil*.txt restjil*.txt
for term in ${files[*]} # Read each file from the array
do
count=0
cat $term | while read LINE # Read the content of each file
do
let count++
autorep -j $LINE -w > test_ps #In order to use the temp file later to add the corressponding condition id
autorep -j $LINE -q > term1.txt # to handle box job we need a temp file
autorep -j $LINE -q >> $term.txt # Keep adding the jil to file for non box jobs
if [ $(grep -i "box:" term1.txt | wc -l) -gt 0 ]; then # handle box jobs
    touch boxjil
    cat term1.txt|while read LINE1; #Parse the box job
  do
    if [ "$LINE1" = "" ]; then #search the jil until it encounters a blank line
       echo $LINE1 >> test_test# write out until you encounter a blank line.
                               # This would give you only the box jil rather then all the child jobs
    fi
  done
    cat $term.txt test_test
fi
exit
if   [ $(grep "kkap" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGSW" >> $term.txt
elif [ $(grep "kkpc" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGT3 " >> $term.txt
elif [ $(grep "kkex" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGSV" >> $term.txt
elif [ $(grep "kkgl" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGSY" >> $term.txt
elif [ $(grep "kkpo" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGSZ " >> $term.txt
elif [ $(grep "kkpa" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTGNH4" >> $term.txt
elif [ $(grep "kktc" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGT4" >> $term.txt
elif [ $(grep "kktr" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGT4" >> $term.txt
else
  echo "condition: " >> $term.txt
fi
done
done
echo -e "\nTotal $count Lines read"

---------- Post updated at 11:59 AM ---------- Previous update was at 11:13 AM ----------

There is some problem with the logic in this section (read the box jil and print till it finds the first new line.

Code:
if [ $(grep -i "box:" term1.txt | wc -l) -gt 0 ]; then # handle box jobs
    cat term1.txt|while read LINE1; #Parse the box job
  do
    if [ "$LINE1" = "" ]; then #search the jil until it encounters a blank line
       echo $LINE1 >> test_test# write out until you encounter a blank line.This would give you only the box jil rather then all the child jobs
    fi
  done
    mv test_test $term.txt
else
autorep -j $LINE -q >> $term.txt # Keep adding the jil to file for non box jobs
fi

---------- Post updated at 12:50 PM ---------- Previous update was at 11:59 AM ----------

I have been able to devise a solution..Pls ignore this request..Thanks

Last edited by vgersh99; 08-29-2013 at 01:18 PM.. Reason: please use code tags not icode!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Comparing two files and list the difference with common first line content of both files

I have two file as given below which shows the ACL permissions of each file. I need to compare the source file with target file and list down the difference as specified below in required output. Can someone help me on this ? Source File ************* # file: /local/test_1 # owner: own #... (4 Replies)
Discussion started by: sarathy_a35
4 Replies

2. Shell Programming and Scripting

search for content in files. Name of files is in another file. Format as report.

Hi I have multiple files in a folder and one file which contains a list of files (one on each line). I was to search for a string only within these files and not the whole folder. I need the output to be in the form File1<tab>string instance 2<tab> string instance 2<tab>string instance 3... (6 Replies)
Discussion started by: pkabali
6 Replies

3. Shell Programming and Scripting

Help related to Script to move files depending on config values

Hi All, I am new to Unix scripting, I have requirement where I need to read the key value pair from config file. Sample Config file: Key(File Pattern) Value(File Directory location) test /Users/Bkumar/Downloads/testdir prod ... (1 Reply)
Discussion started by: sbpkumar7
1 Replies

4. Shell Programming and Scripting

How to split a data file into separate files with the file names depending upon a column's value?

Hi, I have a data file xyz.dat similar to the one given below, 2345|98|809||x|969|0 2345|98|809||y|0|537 2345|97|809||x|544|0 2345|97|809||y|0|651 9685|98|809||x|321|0 9685|98|809||y|0|357 9685|98|709||x|687|0 9685|98|709||y|0|234 2315|98|809||x|564|0 2315|98|809||y|0|537... (2 Replies)
Discussion started by: nithins007
2 Replies

5. Shell Programming and Scripting

write to multiple files depending on file type (solved)

I want a script that will add comments to a file before check-in files. comments depend on type of files. i have a script to list files in the directory that will be checked-in There are xml, js, html, vm files. vm will use comments like c/c++ ( // or /*..*/) can you help me add a comment line... (0 Replies)
Discussion started by: pradeepmacha
0 Replies

6. Shell Programming and Scripting

Help - Script to move files to subdir depending on file extension.

Hi, First off I'm pretty new to scripting so please be gentle. I am looking for some help with a script that will move all files with a certain extension into a folder within their current location. Just for clarity I have all my photos organised in directories such as: ... (4 Replies)
Discussion started by: guinch
4 Replies

7. Shell Programming and Scripting

Split file into multiple files depending upon first 4 digits

Hi All, I have a file like below: 1016D"ddd","343","1299" 1016D"ddd","3564","1299" 1016D"ddd","3297","1393" 1016D"ddd","32989","1527" 1016D"ddd","346498","1652" 2312D"ddd","3269","1652" 2312D"ddd","328","1652" 2312D"ddd","2224","2100" 3444D"ddd","252","2100" 3444D"ddd","2619","2100"... (4 Replies)
Discussion started by: deepakgang
4 Replies

8. Shell Programming and Scripting

split file depending on content

Hi, I have a file which contains records of data. I need to split the file into multiple files depending upon the value of last field. How do i read the last field of each record in the file??? Regards, Chaitrali (4 Replies)
Discussion started by: Chaitrali
4 Replies

9. UNIX for Dummies Questions & Answers

How can I rename multiple files depending on a string occuring in the filenames?

I have many files that have "inputstring" somewhere in their filename (without the quotes), and I want to rename them all so that "inputstring" is replaced with "newstring". And I also want to specify arbitrary text for "inputstring" and "newstring" so that I can call the scripts that does this... (6 Replies)
Discussion started by: karman
6 Replies
Login or Register to Ask a Question