Computing.Net > Forums > Unix > about delimeter

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

about delimeter

Reply to Message Icon

Name: nelsmy
Date: May 11, 2005 at 22:42:05 Pacific
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




Sponsored Link
Ads by Google

Response Number 1
Name: teddybear63
Date: May 11, 2005 at 23:55:42 Pacific
Reply:

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


0

Response Number 2
Name: nails
Date: May 12, 2005 at 04:26:46 Pacific
Reply:

Change the field separator, IFS:

#!/bin/bash

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


0

Response Number 3
Name: David Perry
Date: May 12, 2005 at 04:34:53 Pacific
Reply:

In awk, use the -F flag

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


0

Response Number 4
Name: nelsmy
Date: May 12, 2005 at 17:22:15 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: about delimeter

A question about Unix and Linux www.computing.net/answers/unix/a-question-about-unix-and-linux/3264.html

Is the Mobo about to go www.computing.net/answers/unix/is-the-mobo-about-to-go/1835.html

I've problem about to make script www.computing.net/answers/unix/ive-problem-about-to-make-script/4851.html