永发信息网

linux中编写shell脚本a.out运行时输入a b c

答案:1  悬赏:20  手机版
解决时间 2021-11-19 19:44
  • 提问者网友:雪舞兮
  • 2021-11-18 22:37
linux中编写shell脚本a.out运行时输入a b c
最佳答案
  • 五星知识达人网友:duile
  • 2021-11-18 23:47
[root@zyh shell]# ./only print duplicate line.sh 
Please input your file_path:/root/shell/i
New File:/tmp/i
[root@zyh shell]# cat /tmp/i
abc A
abc B
abd
abcd    A
abcd    B
aaa A
aa
aaa B
[root@zyh shell]# cat only print duplicate line.sh 
#!/bin/bash
read -p "Please input your file_path:" File
cp -p $File /tmp/`basename $File`
file_path=/tmp/`basename $File`
#sort排序并输出,uniq -d 只输出重复行
for record in `sort $file_path | uniq -d`
do
#printf 格式化输出,%cASCII码识别,A的ASCII码是65
        awk 'BEGIN{n=65}{if($0=="'$record'"){printf "%s %c
",$0,n;n+=1} else print}' $file_path > $file_path.new
    mv $file_path.new $file_path
done
echo -n "New File:"
echo $file_path根据楼上作出修改,楼上的我测试的时候没有输出
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯