i am not able to concatenate both the string in shell script as below string
I have below file data as follows.
DSJOBSCHEDULE WWW_GFD_LTPER#XYZ_X0_0001_TEST DESCRIPTION "Stream for source file validation; load; post load checks & archive for Source File" N RUNCYCLE SCHEDID_1 "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR,SA,SU" DSJOBSCHEDULE WWW_GFD_LTPER#XYZ_X0_0002_TEST DESCRIPTION "Stream for source file validation; load; post load checks & archive for Source File" N RUNCYCLE SCHEDID_1 "FREQ=Daily;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR,SA,SU" DSJOBSCHEDULE WWW_GFD_LTPER#XYZ_X0_0003_TEST DESCRIPTION "Stream for source file validation; load; post load checks & archive for Source File" N RUNCYCLE SCHEDID_1 "FREQ=Month;INTERVAL=1;BYDAY=MO" need O/P as below:- XYZ_X0_0001_TEST: FREQ=WEEKLY XYZ_X0_0002_TEST: FREQ=Daily XYZ_X0_0002_TEST: FREQ=Month I tried as below:- I am able to get the XYZ_X0_0001_TEST and FREQ=WEEKLY from file and i am not able to concatenate the above both the string in shell script. cut -d'#' -f2 as.txt|grep XYZ --i will get XYZ_X0_0001_TEST and i am getting the grep -w SCHEDID_1 as.txt|cut -d' ' -f4|cut -d'"' -f2|cut -d';' -f1 = FREQ=WEEKLY |
Code:
awk -F'[#";]' '/XYZ|FREQ/{printf $2 (/XYZ/?": ":"\n")}' file |
I think the tool of choice here would be awk.
I was able to knock up a simple awk script that does the trick. I put the awk in t.awk and pasted your data file into testfile.txt, then... Code:
awk -f t.awk testfile.txt Code:
BEGIN{ ** UPDATE: See what I mean! And grail types faster than I do as well! |
Quote:
|
bash and the other shells can do while loops and other kinds of loops. What are you trying to use are criteria for looping and what have you gotten so far in your script?
|
I tried in so many time
for i in grep -B4 SCHEDID_1 JD_file.txt
do c=grep -B4 SCHEDID_1 JD_file.txt>a.txt a=`grep SCHEDULE a.txt|cut -d'#' -f2` b=`grep -w SCHEDID_1 a.txt` echo "$a:$b" while read line do echo $line b=`grep -w SCHEDID_1 $line` echo "$b" a=`grep SCHEDULE JD_file.txt|cut -d'#' -f2` echo "$a" echo $a : $b done < JD_file.txt --- |
If you are just trying to read in one file a single time, then the grail's excellent awk solution above would work:
Code:
awk -F'[#";]' '/XYZ|FREQ/{printf $2 (/XYZ/?": ":"\n")}' JD_file.txt Code:
tail -f JD_file.txt | awk -F'[#";]' '/XYZ|FREQ/{printf $2 (/XYZ/?": ":"\n")}' |
Not sure I understand what you mean about using a loop? Both your examples are bash type solutions to do exactly what the awk has done. You do realise that the awk will work on the entire file?
Or have we missed something in that you want it as a bash script instead of something else? |
Hi Grail,
Very thanks for your Quick response. in the bench file it is not working properly .. |
sorry it is working as expected i had taken wrong file...thanks grail and marked as Yes
|
Glad you got it sorted, don't forget to mark the question as SOLVED :)
|
i already marked as solved...but we can do it in another way just asking?
|
As per my signature, you need to go to the Thread Tools just above your first post and select it from the drop down :)
|
please let me know this example can be sloved in loop also?
|
Yes I was able to do this in a while loop in bash. Have a go and think along the same lines as the awk solution.
|
All times are GMT -5. The time now is 01:25 AM. |