Man-Ching's ksh scripts

Interesting scripts, but I have another solution to the splitting problem using IFS.

I offer the following, which should work in vanilla bourne shell, with the using the same delimeters as Man-Ching used.

pl.sh

#!/bin/sh

line="$@"       # Save the argument list
IFS="|"         # Make '|' the field seperator

set -- $line    # reset the argument list

for column      # loop through $\*
do      echo $column
done

Giving the same result

./pl.sh `head -1 /etc/passwd | sed 's/:/|/g'`
root
x
0
1
Super-User
/
/sbin/sh

Indeed you could do the whole part in grave accents in a single sed command.

./pl.sh `sed   -e 's/:/|/g' -e 1q /etc/passwd`
root
x
0
1
Super-User
/
/sbin/sh

Which actually goes to demonstrate a bit of unix philosopy. That is, there are many ways to achieve the same end; none is necesarily the best, or more simply, there is more than one right way to do anything.

Comments:

Post a Comment:
Comments are closed for this entry.
About

* - Solaris and Network Domain, Technical Support Centre


Alan is a kernel and performance engineer based in Australia who tends to have the nasty calls gravitate towards him

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Links
Blogroll

No bookmarks in folder

Sun Folk

No bookmarks in folder

Non-Sun Folk
Non-Sun Folks

No bookmarks in folder