Computing.Net > Forums > Unix > about delimeter

about delimeter

Reply to Message Icon

Original Message
Name: nelsmy
Date: May 11, 2005 at 22:42:05 Pacific
Subject: about delimeter
OS: Red hat
CPU/Ram: Pentium 512
Comment:

Dear all,

Anyone can give me some direction on it?

Here is my file content,

aaaaa:bbbbb:ccccc:ddddd
11111:22222:33333333:444
zzzz:dddd:eee:eee

how do i read each column into specific variable with delimeter ":"??

Here my script,anyone can give me some direction on it?

#!/bin/bash
while read v1 v2 v3 v4
do
.......
done < text.txt



Report Offensive Message For Removal


Response Number 1
Name: teddybear63
Date: May 11, 2005 at 23:55:42 Pacific
Subject: about delimeter
Reply: (edit)

hi,
You can do like this:
#!/bin/bash
while read buf
do
v1=`echo $buf|cut -d: -f 1`
v2=`echo $buf|cut -d: -f 2`
.......
done < text.txt


Report Offensive Follow Up For Removal

Response Number 2
Name: nails
Date: May 12, 2005 at 04:26:46 Pacific
Subject: about delimeter
Reply: (edit)

Change the field separator, IFS:

#!/bin/bash

while IFS=":" read v1 v2 v3 v4
do
printf "%s %s \n" $v1 $v2
done < text.txt


Report Offensive Follow Up For Removal

Response Number 3
Name: David Perry
Date: May 12, 2005 at 04:34:53 Pacific
Subject: about delimeter
Reply: (edit)

In awk, use the -F flag

awk -F: '{ print $1 " " $2 " " $3 " " $4 }' text.txt


Report Offensive Follow Up For Removal

Response Number 4
Name: nelsmy
Date: May 12, 2005 at 17:22:15 Pacific
Subject: about delimeter
Reply: (edit)

Dear all,

Really sorry to everyone about that actually this solution have been solved by nail and posted before, but i didn't search deeply so that this msg can be consider is a duplicate message!

Thanks you to everyone who give a hand on it.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: about delimeter

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge