×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

ok. i have another one. it is little bit harder. about csv file re-orginze.

CSV file is well known MS access and Excel file extract. .csv file use CR/LF as record delimiter and ',' as field delimiter. Normally, the value of the field doens't cotnain either CR nor LF. In case when the value is not key in but copy/paste from other source. CR/LF may contains as field value. To mark it as a field, .csv file quote the field value with '"'.

Here is an example(4 columns)
1,bb,33,55
2,"a
c",66,88
3,aa,xx,kk
4,"Y
YY", dd, "ffff
kk"



All togher there are 4 lines, the first field is record number.

The requirement is:
Replace CR/LF by a space, if it is part of the field value. The following is the result after fix:

1,bb,33,55
2,"a c",66,88
3,aa,xx,kk
4,"Y YY", dd, "ffff kk"

Hint, I used sed to do the fix with N command.
Report

Replies, comments and Discussions:

  • 工作学习 / 专业技术讨论 / 贴个unix shell环境的小题目给大家玩玩儿。 输入变量为一不超过10位的整数。要求输出值在输入值pad leading zero to make the length to 10. 看看谁的办法最简洁。 要求:不用使用文件,可以使用管道(pipe).
    my solution is:
    
    outvar=`echo $invar|sed -e 's/\(^.$\)/000000000\1/' -e 's/\(^..$\)/00000000\1/' -e 's/\(^...$\)/0000000\1/' -e 's/\(^....$\)/000000\1/' -e 's/\(^.....$\)/00000\1/' -e 's/\(^......$\)/0000\1/' -e 's/\(^.......$\)/000\1/' -e 's/\(^........$\)/00\1/' -e 's/\(^.........$\)/0\1/'`
    
    
    • how about -- printf "%.10d" $invar
      • en. good, better than mine: outvar=`echo $invar|awk '{printf("%.10d", $1)}'`
        • what's the prize? ^_^
          • en... u can ask.
            • 那就再来一道吧...:D
              • ok. i have another one. it is little bit harder. about csv file re-orginze.
                CSV file is well known MS access and Excel file extract. .csv file use CR/LF as record delimiter and ',' as field delimiter. Normally, the value of the field doens't cotnain either CR nor LF. In case when the value is not key in but copy/paste from other source. CR/LF may contains as field value. To mark it as a field, .csv file quote the field value with '"'.

                Here is an example(4 columns)
                1,bb,33,55
                2,"a
                c",66,88
                3,aa,xx,kk
                4,"Y
                YY", dd, "ffff
                kk"



                All togher there are 4 lines, the first field is record number.

                The requirement is:
                Replace CR/LF by a space, if it is part of the field value. The following is the result after fix:

                1,bb,33,55
                2,"a c",66,88
                3,aa,xx,kk
                4,"Y YY", dd, "ffff kk"

                Hint, I used sed to do the fix with N command.
              • it looks this time no more prize ;)
                • Couldn't google an answer this time :( 作为惩罚就再来一道吧...:D
                  • It is your turn now. 作为惩罚you来一道吧
    • 太复杂。转成string后,前面加10个0,然后取右边10位就行了。
      • 回得太快了,没看到楼上的解答。:)