您可以使用 substr 仅抓取 from 和 subject 的前 n 个字符,因为您知道最多只能玩 60 个字符,您可以抓取 'from' 的第 25 个和 'subject 的第 35 个'。
#!/usr/bin/gawk -f
BEGIN {
# set ouput delimiter to comma
OFS=","
# set input delimiter to bar
FS="|" }
{
f=$1
month=$2
day=$3
year=$4
from=$5
subject=$6
from=substr(from,1,25)
subject=substr(subject,1,35)
printf ("%5d,%3s%.2s,%4s,%s,%s\n",f,month,day,year,from,subject)
}
在这个文件上运行上面的代码
12123|Jan|14|1970|jack@overthehill.com|“生日快乐”
14545|Jan|15|1970|jill@thewell.com|“希望你的头没事”
27676|Feb|14|1970|jack@overthehill.com|“今晚还有吗?”
29898|Feb|14|1970|jill@thewell.com|“当然,如果你带巧克力的话。”
34234|Feb|15|1970|jack@overthehill.com|“昨晚玩得很开心,
希望你也这样做了。等不及周末了,爱杰克”
返回
12123,Jan14,1970,jack@overthehill.com,"Happy birthday"
14545,Jan15,1970,jill@thewell.com,"Hope your head is ok"
27676,Feb14,1970,jack@overthehill.com,"Still on for tonight?"
29898,Feb14,1970,jill@thewell.com,"Sure, if you bring the chocolate."
34234,Feb15,1970,jack@overthehill.com,"Had a great time last night, hope