I am trying to print the remaing fields and field numbers beginning with a field 'xyz'
#cat abc
test1:test2:xyz:test3:test4:test5
#cat def
test1:test2:test3:xyz:test4:test5
desired output is to be able to print NF and any trailing fields separated by':'
test3 3
or
test4 3
or
test5 3
likewise,
test4 2
or
test5 2
placeing a field separator as 'xyz' illiminates using ':' as a second separator or is that possible?
anbu23
March 22, 2007, 12:51pm
2
awk -F: -v OFS="\nor\n" ' { sub(".*xyz:",""); for(i=1;i<=NF;++i) $i=$i" "NF ;print } ' file
I'm gonna use sed for the time being, but would like to know the correct awk syntax as well
cat abc | sed 's/\(.*\)xyz://' | awk -F: '{print $1,NF}'
edit*
thanks, i'll try it
anbu23
March 22, 2007, 12:55pm
4
prkfriryce:
I'm gonna use sed for the time being, but would like to know the correct awk syntax as well
cat abc | sed 's/\(.*\)xyz://' | awk -F: '{print $1,NF}'
edit*
thanks, i'll try it
You can do everything in awk.Check my previous post
yeah works well, a little too well! i was looking for a more simplified version by printing the fields individually, but the 'sub' syntax is what i was looking for. I'll tweek it for future applications.
thanks again