Scripting job to complete


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting job to complete
# 1  
Old 04-15-2011
Scripting job to complete

Hi Friends,

I don't have much experience in shell scripting & have a urgent scripting job to complete. Need your help to do the following.

I have a input file like below:
Code:
CDR #1
----------
Name James
Age 30
Country Japan
 
CDR #2
----------
Name Robin
Age 31
Country Germany
 
CDR #3
----------
Name George
Age 32
Country Australia

I want output like:
Code:
James|30|Japan
Robin|31|Germany
George|32|Australia

Thanks,
Sunil

Last edited by Franklin52; 04-15-2011 at 09:53 AM.. Reason: Please use code tags
# 2  
Old 04-15-2011
make a file test.awk containing
Code:
/Name/ { n=$2 }
/Age/ { a=$2 }
/Country/ { { c=$2;printf "%s|%s|%s\n",n,a,c}
}

Code:
awk -f test.awk yourfile
-> 
James|30|Japan
Robin|31|Germany
George|32|Australia


Last edited by Franklin52; 04-15-2011 at 09:53 AM.. Reason: Please use code tags, thank you
This User Gave Thanks to pbillast For This Post:
# 3  
Old 04-15-2011
pbillast's solution won't work as expected when Name or Country contains more than one word, the following code does:
Code:
awk '/^(Name|Age|Country)/{ $1=""; sub(/^[ \t]+/, ""); if(++i%3){ORS="|"}else{ORS="\n"} print }' inputfile

This User Gave Thanks to kevintse For This Post:
# 4  
Old 04-16-2011
Bug Thanks for your replies.

Thanks for your replies. I will implemet the suggetsed solutions & revert to you guys as soon as possible.

Best Regards,
Sunil
# 5  
Old 04-17-2011
Try this , I have developed the code w.r.t data provided by you .

Code:
#!/bin/ksh

for i in   `grep  -n "-" tempfile.dat |awk -F ':' '{print $1}'`
do
  echo  $i
  idx=`expr $i + 3`
  echo idx : $idx
  echo `sed -n  "$i","$idx"p tempfile.dat|awk  '{print $2}'|tr "\n" " " |awk -F ' ' '{print $1 "|" $2 "|" $3}'` >>newfile.dat
done


Last edited by Franklin52; 04-17-2011 at 11:00 AM.. Reason: Please indent your code and use code tags, thank you
This User Gave Thanks to palanisvr For This Post:
# 6  
Old 04-17-2011
Quote:
Originally Posted by palanisvr
#!/bin/ksh

for i in `grep -n "-" tempfile.dat |awk -F ':' '{print $1}'`
do
echo $i
idx=`expr $i + 3`
echo idx : $idx
echo `sed -n "$i","$idx"p tempfile.dat|awk '{print $2}'|tr "\n" " " |awk -F ' ' '{print $1 "|" $2 "|" $3}'` >>newfile.dat
done


Please use code tags, it only takes less than a second to wrap your code with CODE tags. Without them, reading the code is difficult.
These 2 Users Gave Thanks to matrixmadhan For This Post:
# 7  
Old 04-18-2011
Bug Actual Input file attached

Dear Friends,

Once again thank you all for the help. The input file is now changed by the customer. I am attaching the actual input file. Following is the snippet from the file.

File Header: Size :0 bytes:
Code:
CDR #1
----------
recordType EGSNPDPRECORD
servedIMSI 405150016945607
ggsnAddress 115.255.8.82
chargingID 626709187
sgsnAddress 220.224.141.18
 
CDR #2
----------
recordType EGSNPDPRECORD
servedIMSI 405210010858247
ggsnAddress 115.255.8.83
chargingID 626709171
sgsnAddress 220.224.141.85

There will be mulitiple CDR #n records in the file.

I need a script that will give me output of only the 2nd field for each CDR like below.
Code:
EGSNPDPRECORD|405150016945607|115.255.8.82|626709187|220.224.141.18......
EGSNPDPRECORD|405210010858247|115.255.8.83|626709171|220.224.141.85......

Each CDR should be in a separate line. The script should be able to count the total number of CDR# in the file & genearte CDR as mentioned above for all the CDR's.

Thanks,
Sunil

Last edited by Scott; 04-18-2011 at 02:55 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automation script for email alert when a job get complete with status successful.

Guyz, Please let me know about script which is to be sending an automatic email to particular mail id's when a monotoring job get complete with status successful. (1 Reply)
Discussion started by: Rehan Ahmad
1 Replies

2. Shell Programming and Scripting

To refire a backup job using shell scripting..........

how to write a code using shell scripting to refire a back up job if it fails with an error code of 196? (7 Replies)
Discussion started by: Pawan Ramnani
7 Replies

3. Shell Programming and Scripting

I want a script to view the complete log information of data stage job from UNIX IBM AIX.

Hi, I am working on data stage 8.7 version and I want a script a to view the all log information of the data stage job from UNIX environment. Can you please help me out by give the script. Thanks in advance... (7 Replies)
Discussion started by: victory
7 Replies

4. Windows & DOS: Issues & Discussions

AutoSys Job not waiting for script to complete

I'm not sure if this is the right place to post this issue...but here goes... I am converting a set of windows jobs from Control-M to AutoSys r11.3. The same command line is being executed in both systems. The Control-M job runs to compltion in about 1.5 hours, waiting for the entire batch... (3 Replies)
Discussion started by: ajomarquez
3 Replies

5. Shell Programming and Scripting

Unix Scripting : Sort a Portion of a File and not the complete file

Need to sort a portion of a file in a Alphabetical Order. Example : The user adam is not sorted and the user should get sorted. I don't want the complete file to get sorted. Currently All_users.txt contains the following lines. ############## # ARS USERS ############## mike, Mike... (6 Replies)
Discussion started by: evrurs
6 Replies

6. Post Here to Contact Site Administrators and Moderators

Where can I download the VTC - Unix Shell Scripting Advanced complete video

Where can I download the VTC - Unix Shell Scripting Advanced complete video. I don't know in which thread I should post this question.Plz help me out, or just tell me the link in the reply to this post. Thanks in advance. (0 Replies)
Discussion started by: villain41
0 Replies

7. Shell Programming and Scripting

How to schedule a job in shell scripting.

Hi all I have made a shell script to check jobs' status and send an alert based on the result. I want to run this script to run every 4 hours and I don't have access to cron. Can we schedule using shell scripting instead of cron facility? (2 Replies)
Discussion started by: johnl
2 Replies

8. UNIX for Advanced & Expert Users

At job in SHELL SCRIPTING

Hi I am using at job in my SHELL scripts.. When it prompts to enter the time for at job..I used to press enter(return) button.. After that its running the job properly, but its showing the below error UX:at: ERROR: Bad date specification.. Can some one suggest how to remove that error. ... (2 Replies)
Discussion started by: grajesh_955
2 Replies

9. Windows & DOS: Issues & Discussions

windows scripting for a batch job

I have been doing unix scripting for quite awhile and there seems to be a wealth of information on it. Now I am working on migrating an intel based application to a new server. I need to modify some existing scripts, but am having trouble finding information on windows scripting, a forum similar... (2 Replies)
Discussion started by: MizzGail
2 Replies

10. Shell Programming and Scripting

start job after complete transfer....

Hi, I have a situation... I have a script it checks for a file in a folder which comes to the folder every day at specified time...2am to 4 am, once the file is in the polder my process starts...but the problem is the files being placed are huge and it is even taking half an hour for the file... (3 Replies)
Discussion started by: mgirinath
3 Replies
Login or Register to Ask a Question