Extract record in shell script,so far using awk without success


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract record in shell script,so far using awk without success
# 1  
Old 07-10-2012
Question Extract record in shell script,so far using awk without success

hello, I require help in the following. There is a report similar to the ones shown here. I need to do couple of things
Code:
10/07 12:47            0003210042 R TENN ANVISER0 DELF96A.V1.O.TENRREG       120710 124657 U 00000 DELFOR          1       4331
10/07 12:47            0003210043 S TENN ANVISER0 DELF96A.V1.O.TENRREG       120710 134658 U 00000 DELFOR          1       4244
10/07 15:47            0003210043 S TENN ANVISER0 DELF96A.V1.O.TENRREG       120710 155658 U 00000 DELFOR          1       4244

1> Check for all records which has only "S" in the above records, extract
eg. The second record is "S" (in the 4th col)

2> Pick up the 2nd col and 9th col i.e 12:47 and 134648 to show something like this

So the output should look something like this
Code:
Sch Date/Time       Directn    Destination        File Format           EERP Date/Time
=============      =======    ===========        ===========           ==============
10/07 12:47          S        ANVISER0    DELF96A.V1.O.TENRREG       120710 13:47     
10/07 15:47          S        ANVISER0    DELF96A.V1.O.TENRREG       120710 15:57

I am struggling to get awk to get the display. Would there be an easier way other than awk. The records will be in a separate file

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by vbe; 07-10-2012 at 10:21 AM..
# 2  
Old 07-10-2012
With awk:

Code:
awk '
BEGIN{print "Sch Date/Time\tDirectn\tDestination\tFile Format\t\tEERP Date/Time"
      print "==============\t=======\t===========\t===========\t\t=============="
      OFS="\t"} 
$4=="S"{
hh=substr($9,1,2)
mm=substr($9,3,2)
ss=substr($9,5,2)
$9=(ss+0>=30?(mm==59?(hh==23?"00:00":(hh+1)":00"):(hh":"(mm+1))):(hh":"mm))
print $1" "$2,$4,$6,$7,$8" "$9}' inputfile

Output:
Code:
Sch Date/Time   Directn Destination     File Format             EERP Date/Time
==============  ======= ===========     ===========             ==============
10/07 12:47     S       ANVISER0        DELF96A.V1.O.TENRREG    120710 13:47
10/07 15:47     S       ANVISER0        DELF96A.V1.O.TENRREG    120710 15:57

Change the static text and/or the logic as per your requirement...

Last edited by elixir_sinari; 07-10-2012 at 12:10 PM..
This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 07-11-2012
thank you so much elixir_sinari, it works like charm...Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to execute Oracle procedure and trigerring email on success and failure

Here is the shell script which need to trigger a stored procedure and when the record count is 0 then it should capture in the log that 0 duplicate records are found and if it's more than 0 then log with no of records. Also if there is any sqlerror then it should write the same in the log file and... (17 Replies)
Discussion started by: senmng
17 Replies

2. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

3. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

4. Shell Programming and Scripting

Millions of record using shell script

I wanna create a millions of record using shell scripts.. the scenario is somehow like this,,,i want to create the record for these fields in my database..id,name,addrs,sales. So can you please give a overall idea for how to achieve it? (9 Replies)
Discussion started by: shankarpanda003
9 Replies

5. Shell Programming and Scripting

Save awk record field in bourne shell variable

Hello, I am trying to write a shell script that maintains the health of the passwd file. The goal is to check for duplicate usernames, UID's etc. I am able to find and sort out the UID and login names via awk (which I would like to use), but I can't figure out how to save the record field into a... (1 Reply)
Discussion started by: Learn4Life
1 Replies

6. UNIX for Dummies Questions & Answers

awk script printing each record twice

i have a find command piped to an awk script, I'm expecting it printing the matching record one time but it's doing it twice: the following is my code: find directoryname | awk 'BEGIN { FS="/" } /.*\.$/ || /.*\.$/ { printf "%s/%s\n", $(NF-1), $NF } it gave me the correct output, but just... (2 Replies)
Discussion started by: ymc1g11
2 Replies

7. Shell Programming and Scripting

Script to extract particular record

Hi, I have a large file with huge number of records which are of following pattern: TYPE1 { originNodeType : "IVR" originHostName : "AAIVR" originTransactionID : "01310559" originTimeStamp : "20110620192440+0530" hostName : "hhhh" voucher : '0'D rProfileID : "ZZZZ" Before { Flags :... (1 Reply)
Discussion started by: madhukar1anand
1 Replies

8. Shell Programming and Scripting

Testing success of AWK code in KSH script

I need a bit of help here on something simple. I have a KSH script (must be KSH) that needs to change 2 positional variables in a CSV script. The CSV script looks like this: 00001,010109,01/01/2009 00:01:01 00008,090509,09/05/2009 13:47:26 My AWK script will change $2 and $3 based... (4 Replies)
Discussion started by: kretara
4 Replies

9. Shell Programming and Scripting

Using Awk in shell script to extract an index of a substring from a parent string

Hi All, I am new to this shell scripting world. Struck up with a problem, can anyone of you please pull me out of this. Requirement : Need to get the index of a substring from a parent string Eg : index("Sandy","dy") should return 4 or 3. My Approach : I used Awk function index to... (2 Replies)
Discussion started by: sandeepms17
2 Replies

10. Shell Programming and Scripting

extract data from xml- shell script using awk

Hi, This is the xml file that i have. - <front-servlet platform="WAS4.0" request-retriever="SiteMinder-aware" configuration-rescan-interval="60000"> <concurrency-throttle maximum-concurrency="50" redirect-page="/jsp/defaulterror.jsp" /> - <loggers> <instrumentation... (5 Replies)
Discussion started by: nishana
5 Replies
Login or Register to Ask a Question