Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extracting rows

Status
Not open for further replies.

agilo

Programmer
Feb 4, 2004
73
TR
Hi,

I have a file with entries look like:

Name: xxxx
TelNumber: 234556
E-mail: xxx@zzz
Roomnumber: 32
.....
.....

Name: yyyy
TelNumber: 64556
E-mail: yyyy@zzz
Roomnumber: 22
....
....

I want to extract only the rows "Name", "TelNumber" and "E-mail" and to write them in the form:
Name TelNumber E-mail

Can any body helps..

Thanks in advance...
Agilo


 
You can try something like this:
awk -F: '
/^Name:/{name=$2;next}
/^TelNumber:/{tel=$2;next}
/^E-mail:/{printf "%s\t%s\t%s\n",name,tel,$2}
' /path/to/inputfile >output

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thank you PHV,

I do have one problem when the TelNumber is missing I get the wrong data.. I tried to add the following if condition
before printing; but it does nothing; i still get the same results...

/^E-mail:/{
if (TelNumber !~ " ")
printf "%s\t%s\t%s\n",name,tel,$2}


I just want to add the condition, if the TelNumber is empty, do not print the whole line (name, TelNumber and E-mail)..

Can you please, tell me what is wrong with this if condition.

Thanks in advance,

Agilo
 
Try

/^E-mail:/ && tel{printf "%s\t%s\t%s\n",name,tel,$2;tel=""}


CaKiwi
 
[tt]
BEGIN{ FS=": *"; fmt="%-20s%-12s%s\n"
printf fmt,"Name","TelNumber","E-mail"}
/^Name:/ {name=$2}
/^TelNumber:/ {tel=$2}
/^E-mail:/ && tel {printf fmt,name,tel,$2; tel=""}
[/tt]
 
agilo, try this for your condition:
/^E-mail:/{
if (TelNumber ~ "[0-9]")
printf "%s\t%s\t%s\n",name,tel,$2}

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks guys... It works fine now .
 
No idea how i would go about this, completly new to awk, but does anyone know how i would do the following :

I need to pull from a file all lines where the line has AddressStringDigits in it and CallTypeLevel1,2 &3... and enter into a new file

For example :

CDR 25,( AddressStringDigits 0x"0034607311112f"),(CallTypeLevel1 0x"02") -- 2,( CallTypeLevel2 0x"02") -- 2,
( CallTypeLevel3 0x"01") -- 1
CDR 26,( AddressStringDigits 0x"0034686830367f"),
( CallTypeLevel1 0x"02") -- 2,( CallTypeLevel2 0x"02") --2,
( CallTypeLevel3 0x"01") -- 1

Would be taken from :


-- CDR 25
( MobileOriginatedCall
( MoBasicCallInformation
( SimChargeableSubscriber
( Imsi 0x"214015001189242f")
)
( Destination
( TypeOfNumber 0x"00") -- 0
( NumberingPlan 0x"01") -- 1
( AddressStringDigits 0x"0034607311112f")
)
( CallEventStartTimeStamp
( LocalTimeStamp "20040224082330") -- 0x"3230303430323234303832333330"
( UtcTimeOffsetCode "/") -- 0x"2f", 47
)
( TotalCallEventDuration "6") -- 0x"36", 54
)
( LocationInformation
( NetworkLocation
( RecEntityCode 0x"07") -- 7
( LocationArea 0x"0145") -- 325
)
)
( BasicServiceUsedList
( BasicServiceUsed
( BasicService
( TeleServiceCode "11") -- 0x"3131", 12593
)
( ChargeInformationList
( ChargeInformation
( ChargedItem "D") -- 0x"44", 68
( ExchangeRateCode 0x"01") -- 1
( CallTypeGroup
( CallTypeLevel1 0x"02") -- 2
( CallTypeLevel2 0x"02") -- 2
( CallTypeLevel3 0x"01") -- 1
( CalledCountryCode "34") -- 0x"3334", 13108
)
( ChargeDetailList
( ChargeDetail
( ChargeType "00") -- 0x"3030", 12336
( Charge 0x"02a5") -- 677
( ChargeableUnits "6") -- 0x"36", 54
( DayCategory "I") -- 0x"49", 73
( TimeBand "I") -- 0x"49", 73
)
)
)
)
( DataVolumeReference 0x"00") -- 0
)
)
( CamelServiceUsed
( AddressStringDigits 0x"1134607009902f")
( CamelServiceLevel 0x"00") -- 0
( CamelServiceKey 0x"0d1d") -- 3357
( CamelCallReference
( AddressStringDigits 0x"447953706101")
( CamelCallReferenceNumber "1621819392") -- 0x"31363231383139333932"
)
)
)
-- CDR 26
( MobileOriginatedCall
( MoBasicCallInformation
( SimChargeableSubscriber
( Imsi 0x"214012001453079f")
)
( Destination
( TypeOfNumber 0x"01") -- 1
( NumberingPlan 0x"01") -- 1
( AddressStringDigits 0x"0034686830367f")
)
( CallEventStartTimeStamp
( LocalTimeStamp "20040224082207") -- 0x"3230303430323234303832323037"
( UtcTimeOffsetCode "/") -- 0x"2f", 47
)
( TotalCallEventDuration 0x"09") -- 9
)
( LocationInformation
( NetworkLocation
( RecEntityCode 0x"0d") -- 13
( LocationArea 0x"01b6") -- 438
)
)
( BasicServiceUsedList
( BasicServiceUsed
( BasicService
( TeleServiceCode "11") -- 0x"3131", 12593
)
( ChargeInformationList
( ChargeInformation
( ChargedItem "D") -- 0x"44", 68
( ExchangeRateCode 0x"01") -- 1
( CallTypeGroup
( CallTypeLevel1 0x"02") -- 2
( CallTypeLevel2 0x"02") -- 2
( CallTypeLevel3 0x"01") -- 1
( CalledCountryCode "34") -- 0x"3334", 13108
)
( ChargeDetailList
( ChargeDetail
( ChargeType "00") -- 0x"3030", 12336
( Charge 0x"02a5") -- 677
( ChargeableUnits 0x"09") -- 9
( DayCategory "I") -- 0x"49", 73
( TimeBand "I") -- 0x"49", 73
)
)
)
)
( DataVolumeReference 0x"00") -- 0
)
)
( CamelServiceUsed
( AddressStringDigits 0x"1134607009901f")
( CamelServiceLevel 0x"00") -- 0
( CamelServiceKey 0x"0d1c") -- 3356
( CamelCallReference
( AddressStringDigits 0x"447953710103")
( CamelCallReferenceNumber "1809907712") -- 0x"31383039393037373132"
)
)
)

I hope someone can make some sense of this...!!

Many thanks to whoever can help.

Nick
 
Hi,

I have the following two files.

File1:

x1 x2 x3 x4 x5
name1 12 34 43 3
name2 44 34 76 76
name3 21 23 21 23
name4 5 67 76 76

and File2:

x1 x2 x3 x4 x5
name1 12 34 43 3
name3 21 23 21 23
name7 32 43 23 32

I want to write out the missing lines from Files2 (which exist in File1) and the added (new)lines in File2 (which do not exist in File1) into two seperate output files.

Any ideas are welcomed...

Thanks in advance,

Agilo

 
man comm

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top