Powered by Invision Power Board


  Reply to this topicStart new topicStart Poll

> spliting text having multiple delimiter, spliting text having multiple delimiter
im4vip
Posted: Apr 21 2005, 03:59 PM
Quote Post


Newbie
*

Group: Members
Posts: 8
Member No.: 890
Joined: 27-March 05



All,
Can some tell me how can I split a file into columns which has multiple de-limiter.

i.e
I have a file looks like

Source of delivery: dbCristal
Report date of data: 01.04.2005
Date of interface creation: 21.04.2005:11.12.01
aa.txt: 14791;bb.txt: 11709;cc.txt: 10839;

My output need to be :

aa.txt,14791
bb.txt, 11709
cc.txt, 10839

Can this be accompolished using awk/shell script ?

Regs
Srn
PMEmail Poster
Top
vibhor_agarwalin
Posted: Apr 22 2005, 07:58 AM
Quote Post


User Level: 3
***

Group: Members
Posts: 34
Member No.: 788
Joined: 1-February 05



Will something like this work

sed -e 's/:/,/g' | awk -F";" '{print $1,"\n",$2, ...}
PMEmail Poster
Top
im4vip
Posted: Apr 22 2005, 12:50 PM
Quote Post


Newbie
*

Group: Members
Posts: 8
Member No.: 890
Joined: 27-March 05



Hi,
Thanks, However is there a way I can discard the all the lines above the required data i.e in this case required line is no 4, so i need to discard line 1,2,3.

1 Source of delivery: dbCristal
2 Report date of data: 01.04.2005
3 Date of interface creation: 21.04.2005:11.12.01
4 aa.txt: 14791;bb.txt: 11709;cc.txt: 10839;

many thanks

PMEmail Poster
Top
vibhor_agarwalin
Posted: Apr 25 2005, 05:02 AM
Quote Post


User Level: 3
***

Group: Members
Posts: 34
Member No.: 788
Joined: 1-February 05



Just extend a bit.

cat file | grep ";" | sed -e 's/:/,/g' | awk -F";" '{print $1,"\n",$2, ...}
PMEmail Poster
Top
andyb1ack
Posted: Apr 26 2005, 03:40 PM
Quote Post


User Level: 4
****

Group: Members
Posts: 98
Member No.: 513
Joined: 9-September 04



You can replace all the ";" with an carriage return. I've done it here by escaping the carriage return (with a "\").

CODE

$ cat /var/tmp/asb
Source of delivery: dbCristal
Report date of data: 01.04.2005
Date of interface creation: 21.04.2005:11.12.01
aa.txt: 14791;bb.txt: 11709;cc.txt: 10839;

$ sed 's/;/\
/g' /var/tmp/asb
Source of delivery: dbCristal
Report date of data: 01.04.2005
Date of interface creation: 21.04.2005:11.12.01
aa.txt: 14791
bb.txt: 11709
cc.txt: 10839
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
« Next Oldest | Shells & Scripting | Next Newest »

Topic Options Reply to this topicStart new topicStart Poll

 



[ Script Execution time: 0.2835 ]   [ 12 queries used ]   [ GZIP Enabled ]




Partners: Cambridge Plus :: <Link Available> :: Electronic Design Bedfordshire :: <Link Available>
Unix Man Pages / Linux Man Pages :: HiFi Forum :: SIP VoIP Phone & Provider Reviews :: UNIX/Linux Forum Archives

More info on advertising on Unix/Linux Forum