first ahead of time of you, hope part of day. have file list of lines 5 parameters long. such
bob:wilson:nebraska:34:yes
i need write program in bash allow me view standard out put horizontally , allow me call lines of text in file like
$sh filename.sh 1
bob tom dave etc..
or
$sh filename.sh 1 3 4 2
bob:nebraska:34:wilson tom:iowa:27:anderson etc..
what have written far
cut -d : -f$1,$2,$3,$4,$5 somefile.txt | paste -s
the problem if user puts in less 5 parameters after sh filename.sh error code. user not required put in 5 can call 5.
awk
rescue!
awk -f: -v c="$1 $2 $3 $4 $5" 'begin {n=split(c,a," ")} {for(i=1;i<n;i++) printf "%s", $a[i] fs; printf "%s\n", $a[n]}' file
try , let me know if need clarification.
Comments
Post a Comment