[Solved] How to swap PIPE seperator delimiter?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] How to swap PIPE seperator delimiter?
# 1  
Old 04-19-2013
[Solved] How to swap PIPE seperator delimiter?

I have file like below
1|4|OR|OLAP|INT|INT||CONSTANT|2012/08/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36522|55791|LNR|
2|4|OR|OLAP|CLR|CLR||CONSTANT|2012/09/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36522|57891|REGS|
11|5|S1|MRD|RMPLT|RMPLT||CONSTANT|2012/09/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36524|57921|PDR|
411|5|S1|MRD|PRDLP|PRDLP||CONSTANT|2012/08/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36542|57391|PDR|

I want to swap 3rd value to 4th value in the file
example

1|4|OLAP|OR|INT|INT||CONSTANT|2012/08/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36522|55791|LNR|
2|4|OLAP|OR|CLR|CLR||CONSTANT|2012/09/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36522|57891|REGS|
11|5|MRD|S1|RMPLT|RMPLT||CONSTANT|2012/09/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36524|57921|PDR|
411|5|MRD|S1|PRDLP|PRDLP||CONSTANT|2012/08/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36542|57391|PDR|

I tried using following, but its working only if space not PIPE, help
awk '{ t=$3 ; $3=$4; $4=t; print }' _mse_model_val_code_master.dat > outputfile
# 2  
Old 04-19-2013
Yes, you have to specify the field separator to be the pipe:
Code:
$ awk 'BEGIN { FS=OFS="|" } { t=$3; $3=$4; $4=t; print }' input
1|4|OLAP|OR|INT|INT||CONSTANT|2012/08/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36522|55791|LNR|
2|4|OLAP|OR|CLR|CLR||CONSTANT|2012/09/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36522|57891|REGS|
11|5|MRD|S1|RMPLT|RMPLT||CONSTANT|2012/09/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36524|57921|PDR|
411|5|MRD|S1|PRDLP|PRDLP||CONSTANT|2012/08/07|9999/12/31|0|0|0|0|PRL|-358.1684563||||||||||36542|57391|PDR|

# 3  
Old 04-20-2013
Thanks for quick responce and it works fine..Smilie

Moderator's Comments:
Mod Comment edit by bakunin: thanks for the follow-up, chnaged thread title to "Solved"

Last edited by bakunin; 04-20-2013 at 07:00 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace delimiter for a particular column in a pipe delimited file

I have an input file as below Emp1|FirstName|MiddleName|LastName|Address|Pincode|PhoneNumber 1234|FirstName1|MiddleName2|LastName3| Add1 || ADD2|123|000000000 Output : 1234|FirstName1|MiddleName2|LastName3| Add1 ,, ADD2|123|000000000 OR 1234,FirstName1,MiddleName2,LastName3, Add1 ||... (2 Replies)
Discussion started by: styris
2 Replies

2. Shell Programming and Scripting

Replace CRLF between pipe (|) delimiter with LF

Hi Folks! Need a solution for the following :- Source data ------------- 123|123|<CRLF><CRLF><CRLF>|321<CRLF> Required output ------------------ 123|123|<LF><LF><LF>|321<CRLF> <CRLF> represents carriage return <LF> represents line feed Being hunting high and low for a... (10 Replies)
Discussion started by: hishamzz
10 Replies

3. Shell Programming and Scripting

Problem in using cut command with pipe as a delimiter while using in a script

There is a text file in my project named as "mom.txt" in which i want to have contents like.................. LSCRM(Application Name): 1: This is my first application. 2: Today we did shell scripting automation for this app. 3: It was really a good fun in doing so. 4: Really good.| (Here i... (7 Replies)
Discussion started by: Abhijeet Anand
7 Replies

4. Shell Programming and Scripting

Removing duplicate lines on first column based with pipe delimiter

Hi, I have tried to remove dublicate lines based on first column with pipe delimiter . but i ma not able to get some uniqu lines Command : sort -t'|' -nuk1 file.txt Input : 38376KZ|09/25/15|1.057 38376KZ|09/25/15|1.057 02006YB|09/25/15|0.859 12593PS|09/25/15|2.803... (2 Replies)
Discussion started by: parithi06
2 Replies

5. Red Hat

Converting fixed width file to pipe delimiter in Linux(red-hat)

Hi, I am facing a typical scenario for AWK command . In HP- UNIX is behave as expected but in red hat linux same awk code is not give the same result. The below code is for convert the fixed width file to pipe delimiter file in HP-unix server. awk code: #!/bin/awk -f NR!=1... (11 Replies)
Discussion started by: brij_abhi
11 Replies

6. Shell Programming and Scripting

[Solved] Insert tabs as delimiter

Hello all, I have an unstructured file with space as delimiter , which I want to structure. The output file should actually have only 5 columns with tab as delimiter. The 4th column can have only 3 values ( biological_process , cellular_component , molecular_function ) Here is how the... (12 Replies)
Discussion started by: ritakadm
12 Replies

7. Shell Programming and Scripting

[Solved] How to use delimiter

Hi, I am using below script to get the below given output. But i am wondering how to pick the names from below output. Script: echo "dis ql(*) cluster(CT.CL.RIBRSBT3)"| runmqsc CT.QM.701t8|egrep QUEUE|sed -e 's/QUEUE(/ /'|sed -e 's/)/ /' Output: ... (10 Replies)
Discussion started by: darling
10 Replies

8. Hardware

[Solved] Boot Lockup After Drive Swap

Hey All, Im using Fedora 2.6 (which is cannot be changed for compatibility reasons). I cloned a drive from a different server and when i added this drive to a new box, during startup it hangs on "Configuring Kernel Parameters:" Is there any way to bypass this process and still boot... (0 Replies)
Discussion started by: robfwauk
0 Replies

9. UNIX for Dummies Questions & Answers

replacing space with pipe(delimiter)

Hello All, I have a file with thousands of records: eg: |000222|123456987|||||||AARONSON| JOHN P|||PRIMARY |P |000111|567894521|||||||ATHENS| WILLIAM k|||AAAA|L Expected: |000222|123456987|||||||AARONSON| JOHN |P|||PRIMARY |P |000111|567894521|||||||ATHENS| WILLIAM |k|||AAAA|L I... (6 Replies)
Discussion started by: OSD
6 Replies

10. UNIX for Dummies Questions & Answers

Cutting a portion of a line seperated by pipe delimiter

Hi, In the below line a|b|10065353|tefe|rhraqs|135364|5347575 dgd|rg|4333|fhra|grhrt|46423|urdsgd Here i want to cut the characters in between the second and third pipe delimiter and then between fifth and sixth delimiter and retain the rest of the line. My output should be ... (3 Replies)
Discussion started by: ragavhere
3 Replies
Login or Register to Ask a Question