Swapping fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Swapping fields
# 1  
Old 06-12-2013
Swapping fields

Hallo Team,

This is the command that i am running :

Code:
grep ",Call Forward Not Reachable" *2013*

this is the output that i am getting (i did a head -10 but the files can be more than 1000)

Code:
BW-CDR-20130607092500-2-AC162DB137C8-027539-000.csv_rejected_3852983-20130611224135.log:0020234179AC162DB137C820130607071938.5530+020000,MCCARTHY,Normal,+27745102865,,Originating,+27745102865,Anonymous,0123345500,20130607071938.553,0+020000,Yes,20130607071951.278,20130607072049.539,016,VoIP,,0123345500,private,,,,remote,Group,,G729/8000,,,,,,HIP-TOYOTA-DIV-OFFICE,PA (HIP-TOYOTA-DIV-OFFICE),,,+27123345569,Public,unavailable,+27123345569,Public,unavailable,n,,,633053325:0A,633053373:0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0123345569@isvoip.net,PORTIA SETLHARE,Public,,,,,,,,,,,,,,,,,,,,,,,,633053325:0,Call Forward Not Reachable,,,,,,,,,58.261,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Group,,,,,,,,,,,,,,,,+27123345569,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,|Y,ACCOUNT NOT FOUND (9)
BW-CDR-20130610124000-2-AC162DB137C8-028442-000.csv_rejected_3852410-20130611223822.log:0023344926AC162DB137C820130610103222.7980+020000,SEESA,Normal,+27343264503,,Originating,+27343123909,Public,0873509090,20130610103222.798,0+020000,Yes,20130610103239.895,20130610103557.501,016,VoIP,,0873509090,private,,,,remote,Group,,G729/8000,,,,,,HIP-SEESA-NEWCASTLE,Admin (HIP-SEESA-NEWCASTLE),,,+27343264503,Public,unavailable,+27343123909,Public,unavailable,n,,,645911949:0A,645911953:0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0343123909@isvoip.net,Rina Visser,Public,,,,,,,,,,,,,,,,,,,,,,,,645911949:0,Call Forward Not Reachable,,,,,,,,,197.605,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Group,,,,,,,,,,,,,,,,+27343123909,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,|Y,ACCOUNT NOT FOUND (9)
BW-CDR-20130611111000-2-AC162DB137C8-028712-000.csv_rejected_3853572-20130611224551.log:0025103889AC162DB137C820130611090905.9390+020000,MCCARTHY,Normal,+27123238041,,Originating,+27123238041,Public,0123345500,20130611090905.939,0+020000,Yes,20130611090909.598,20130611090914.139,016,VoIP,,0123345500,private,,,,remote,Group,,G729/8000,,,,,,HIP-TOYOTA-DIV-OFFICE,Debtors (HIP-TOYOTA-DIV-OFFICE),,,+27123345534,Public,unavailable,+27123345534,Public,unavailable,n,,,652445523:0A,652445527:0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0123345534@isvoip.net,PORTIA SETLHARE,Public,,,,,,,,,,,,,,,,,,,,,,,,652445523:0,Call Forward Not Reachable,,,,,,,,,4.540,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Group,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,|Y,ACCOUNT NOT FOUND (9)
BW-CDR-20130611112000-2-AC162DB137C8-028714-000.csv_rejected_3853390-20130611224431.log:0025137049AC162DB137C820130611091711.4950+020000,MCCARTHY,Normal,+27123345534,,Originating,+27123238041,Public,0123345500,20130611091711.495,0+020000,Yes,20130611091718.015,20130611091723.068,016,VoIP,,0123345500,private,,,,remote,Group,,G729/8000,,,,,,HIP-TOYOTA-DIV-OFFICE,Debtors (HIP-TOYOTA-DIV-OFFICE),,,+27123238041,Public,unavailable,+27123345534,Public,unavailable,n,,,652553811:0A,652553815:0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0123345534@isvoip.net,PORTIA SETLHARE,Public,,,,,,,,,,,,,,,,,,,,,,,,652553811:0,Call Forward Not Reachable,,,,,,,,,5.052,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Group,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,|Y,ACCOUNT NOT FOUND (9)
BW-CDR-20130611112000-2-AC162DB137C8-028714-000.csv_rejected_3853390-20130611224431.log:0025137607AC162DB137C820130611091628.3410+020000,SEESA,Normal,+27343123909,,Originating,+27820967774,Public,0873509090,20130611091628.341,0+020000,Yes,20130611091632.905,20130611091731.831,016,VoIP,,0873509090,private,,,,remote,Group,,G729/8000,,,,,,HIP-SEESA-NEWCASTLE,Admin (HIP-SEESA-NEWCASTLE),,,+27820967774,Public,unavailable,+27343123909,Public,unavailable,n,,,652544549:0A,652544553:0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0343123909@isvoip.net,Rina Visser,Public,,,,,,,,,,,,,,,,,,,,,,,,652544549:0,Call Forward Not Reachable,,,,,,,,,58.923,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Group,,,,,,,,,,,,,,,,+27343123909,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,|Y,ACCOUNT NOT FOUND (9)
BW-CDR-20130611112500-2-AC162DB137C8-028715-000.csv_rejected_3852909-20130611224109.log:0025153759AC162DB137C820130611092113.8390+020000,MCCARTHY,Normal,+27123238041,,Originating,+27123238041,Public,0123345500,20130611092113.839,0+020000,Yes,20130611092122.634,20130611092128.481,016,VoIP,,0123345500,private,,,,remote,Group,,G729/8000,,,,,,HIP-TOYOTA-DIV-OFFICE,Debtors (HIP-TOYOTA-DIV-OFFICE),,,+27123345534,Public,unavailable,+27123345534,Public,unavailable,n,,,652607275:0A,652607279:0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0123345534@isvoip.net,PORTIA SETLHARE,Public,,,,,,,,,,,,,,,,,,,,,,,,652607275:0,Call Forward Not Reachable,,,,,,,,,5.846,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Group,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,|Y,ACCOUNT NOT FOUND (9)
BW-CDR-20130611113500-2-AC162DB137C8-028717-000.csv_rejected_3853523-20130611224527.log:0025193103AC162DB137C820130611092825.8640+020000,SEESA,Normal,+27741411224,,Originating,+27741411224,Anonymous,0873509090,20130611092825.864,0+020000,Yes,20130611092831.376,20130611093049.536,016,VoIP,,0873509090,private,,,,remote,Group,,G729/8000,,,,,,HIP-SEESA-NEWCASTLE,Admin (HIP-SEESA-NEWCASTLE),,,+27343123909,Public,unavailable,+27343123909,Public,unavailable,n,,,652705171:0A,652705175:0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0343123909@isvoip.net,Rina Visser,Public,,,,,,,,,,,,,,,,,,,,,,,,652705171:0,Call Forward Not Reachable,,,,,,,,,138.159,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Group,,,,,,,,,,,,,,,,+27343123909,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,|Y,ACCOUNT NOT FOUND (9)
BW-CDR-20130611115500-2-AC162DB137C8-028721-000.csv_rejected_3852889-20130611224105.log:0025292959AC162DB137C820130611095426.4120+020000,MCCARTHY,Normal,+27123621921,,Originating,+27123621921,Public,0123345500,20130611095426.412,0+020000,Yes,20130611095442.216,20130611095444.860,016,VoIP,,0123345500,private,,,,remote,Group,,G729/8000,,,,,,HIP-TOYOTA-DIV-OFFICE,Debtors (HIP-TOYOTA-DIV-OFFICE),,,+27123345534,Public,unavailable,+27123345534,Public,unavailable,n,,,653055085:0A,653055089:0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0123345534@isvoip.net,PORTIA SETLHARE,Public,,,,,,,,,,,,,,,,,,,,,,,,653055085:0,Call Forward Not Reachable,,,,,,,,,2.643,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Group,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,|Y,ACCOUNT NOT FOUND (9)
BW-CDR-20130611121000-2-AC162DB137C8-028724-000.csv_rejected_3852301-20130611223740.log:0025345156AC162DB137C820130611100743.3810+020000,SEESA,Normal,+27835550491,,Originating,+27835550491,Public,0873509090,20130611100743.381,0+020000,Yes,20130611100748.020,20130611100816.376,016,VoIP,,0873509090,private,,,,remote,Group,,G729/8000,,,,,,HIP-SEESA-NEWCASTLE,Admin (HIP-SEESA-NEWCASTLE),,,+27343123909,Public,unavailable,+27343123909,Public,unavailable,n,,,653224439:0A,653224443:0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0343123909@isvoip.net,Rina Visser,Public,,,,,,,,,,,,,,,,,,,,,,,,653224439:0,Call Forward Not Reachable,,,,,,,,,28.355,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Group,,,,,,,,,,,,,,,,+27343123909,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,|Y,ACCOUNT NOT FOUND (9)
BW-CDR-20130611123500-2-AC162DB137C8-028729-000.csv_rejected_3852265-20130611231111.log:0025433349AC162DB137C820130611103158.7230+020000,NATIONAL GAMBLING BOARD,Normal,+27720554307,,Originating,+27720554307,Public,0722600158,20130611103158.723,0+020000,Yes,20130611103208.712,20130611103253.498,016,VoIP,,0722600158,national,mobi,0722600158,,remote,10.0.108.21:5060,BW123158724110613-129535791@196.35.130.5,G729/8000,,,,,,HIP-NGB-ECOPARK,Centurion (HIP-NGB-ECOPARK),,,+27100033480,Public,unavailable,+27100033480,Public,unavailable,y,public,,653515435:0A,,,,,,,,,,,,,,cigZYFId~WPLAAIDBXHMBVJClgE-,10.31.36.37,pst.vodacom.co.za,pst.vodacom.co.za,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0100033480@isvoip.net,,,,,,,,,,,,,,,,,,,,,,,,,,653515435:0,Call Forward Not Reachable,,,,,,,,,54.385,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Network,,,,,,,,,,,,,,,,+27100033480,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,|Y,ACCOUNT NOT FOUND (9)

I would like to swap field4 with filed36 and field36 with field4. The names of the files and everything should remain as it is except field 4 and 36.

I thank you in advance and many blessings.

Last edited by Corona688; 06-12-2013 at 01:17 PM..
# 2  
Old 06-12-2013
Code:
awk -F"," -v OFS="," '{ T=$4 ; $4=$36 ; $36=T } 1'

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 06-12-2013
Code:
grep ",Call Forward Not Reachable" *2013* | awk 'BEGIN{OFS=FS=","}; {a=$4; $4=$36; $36=a;}1'

This User Gave Thanks to PikK45 For This Post:
# 4  
Old 06-12-2013
Come to think of it, if you're using awk, you don't need grep too.

Code:
awk '/",Call Forward Not Reachable"/, { T=$4 ; $4=$36 ; $36=T } 1' *2013*

# 5  
Old 06-12-2013
Did you mean-

Code:
awk -F","  '/",Call Forward Not Reachable"/, { T=$4 ; $4=$36 ; $36=T } 1' *2013*

Input appears to be a csv file.
These 2 Users Gave Thanks to jim mcnamara For This Post:
# 6  
Old 06-13-2013
Code:
-bash-3.2$ awk -F","  '/",Call Forward Not Reachable"/, { T=$4 ; $4=$36 ; $36=T } 1' *2013*
awk: /",Call Forward Not Reachable"/, { T=$4 ; $4=$36 ; $36=T } 1
awk:                                  ^ syntax error


Last edited by Scott; 06-13-2013 at 08:09 AM.. Reason: Code tags
# 7  
Old 06-13-2013
Quote:
Originally Posted by Corona688
Come to think of it, if you're using awk, you don't need grep too.

Code:
awk '/",Call Forward Not Reachable"/, { T=$4 ; $4=$36 ; $36=T } 1' *2013*

Excellent!! A very good example of how powerful awk is! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Swapping

Hi Guys I am using SPARC-T4 (chipid 0, clock 2998 MHz), SunOS 5.10 Generic_150400-38 sun4v. How do I see if the server was doing some swapping like yesterday? I had a java application error with java.lang.OutOfMemoryError, now I want to check if the server was not doing some swapping at... (4 Replies)
Discussion started by: Phuti
4 Replies

2. Shell Programming and Scripting

Swapping/replacing fields

Hallo Team, I would like to replace filed 4 and 7 with filed 39 how can i achieve this ? -bash-3.2$ cat dip1.csv| cut -f4,7,24,36,39 -d","|sort -u +27113996891,+27113996891,196.35.130.52,828854047,+27873500077 +27116452690,+27825702918,10.0.109.13:5060,+27116452690,+27116452690... (2 Replies)
Discussion started by: kekanap
2 Replies

3. Shell Programming and Scripting

Swapping of fields in file

Hi Friends , I have file1.txt 1|b|46|123|47673|348738 2|c|63|124|7346|4783 3|y|45|125|5555|78789 output should swap the 4th field to the first field. output 123|1|b|46|47673|348738 124|2|c|63|7346|4783 125|3|y|45|5555|78789 (3 Replies)
Discussion started by: i150371485
3 Replies

4. Shell Programming and Scripting

AWK swapping fields on different lines

Hi All, Sorry if this question has been posted elsewhere, but I'm hoping someone can help me! Bit of an AWK newbie here, but I'm learning (slowly!) I'm trying to cobble a script together that will save me time (is there any other kind?), to swap two fields (one containing whitespace), with... (5 Replies)
Discussion started by: Bravestarr
5 Replies

5. Shell Programming and Scripting

Swapping three lines

I have some text: <date>some_date</date> <text>some_text</text> <name>some_name<name> and I want to transform it to smthng like that: some_name on some_date: some_text I've tried sed: sed 's/<text>\(.*\)<\/text> <name>\(.*\)<\/name>/\2 - \1/' but it says unterminated... (13 Replies)
Discussion started by: dsjkvf
13 Replies

6. Homework & Coursework Questions

Swapping Fields with Sed

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The assignment is to convert a text table to csv format. I've got the cleaning up done, but I need to swap two... (0 Replies)
Discussion started by: VoiceInADesert
0 Replies

7. Shell Programming and Scripting

Swapping of fields in a file

Hi I have afile with 15fields,say f1,f2....f15 delimited on comma. How can i swap the f1,f15 fields using unix shell commands or any script? Thanks (3 Replies)
Discussion started by: ksailesh
3 Replies

8. UNIX for Dummies Questions & Answers

Swapping in VI editor

Hi, I am attempting to replace several similar words with another word in vi. Here is what I have written for the script: 3dTcat -prefix SuperBrik_4WAY_HRF ../JULY10_2007A/results2TENT/stats.JULY10_2007A+tlrc ../JULY10_2007G/results2TENT/stats.JULY10_2007G+tlrc... (1 Reply)
Discussion started by: Jahn
1 Replies

9. SuSE

Swapping

Hello! Why does my SuSE GNU/Linux machine swap? I have a Gig of ram, currently 14MBs of free RAM, 724MB - buffers and caches... That is 685MB of cached RAM, then kernel really should'nt have to swap, It should release cached memory in my thinkin... It has only swaped 3MB's but still,... (3 Replies)
Discussion started by: Esaia
3 Replies

10. UNIX for Dummies Questions & Answers

how to get swapping info

Hi How can I determine if swapping is occuring on a server. Thanks, Leo (2 Replies)
Discussion started by: leo
2 Replies
Login or Register to Ask a Question