Remove prefix using awk

Remove prefix using awk

File:

 nawk -F"|" '{if ($1 ~ /^xyz./) print; else { gsub(.*\..*, \..*, $1) ;print }}' file

Error:

ouput required:

check the syntax of your gsub().

how about below shell?

while read line;do
set $line
echo ${1#*.}
done < yourfile

check your output.

sed -n '/^xyz\./p;/^xyz\./!{s/^[^.|]*\.\(.*\)/\1/p}' filename

op:

xyz.amp|x|a|t
xyz.tmpx|a|t
klmx|a|t
djn|a|t
djn|j|k
iuy|a|t

Or using awk:

awk -F "|" '/^xyz\./{print;next}{sub(/^[^.]*\./,"",$1);print}' OFS="|" filename
xyz.amp|x|a|t
xyz.tmpx|a|t
klmx|a|t
djn|a|t
djn|j|k
iuy|a|t

-Devaraj Takhellambam

Or shorter:

awk '!/xyz/{sub(".*\.","")}1' file