On 02/02/2011 17:33, gene golub wrote:
Can you please help me: I have file with lines:
aaa
bbb
ccc

I need to produce:
'aaa'
'bbb'
'ccc'


Here's the simplest thing I could think of.

Just use

print "'$line'"

Here's a demonstration:

/Users/henk/src/gene-golub$ cat run
input=test/sample
expected=$(<test/expected)

result=$(
    exec < $input
    while read line; do
        print "'$line'"
    done
)

[[ $result == $expected ]] && echo ok
/Users/henk/src/gene-golub$ ksh run
ok

(detailed trace below the signoff)

Cheers,

Henk



/Users/henk/src/gene-golub$ ksh -x run
+ input=test/sample
+ 0< test/expected
+ expected=$'\'aaa\'\n\'bbb\'\n\'ccc\''
+ exec
+ 0< test/sample
+ read line
+ print $'\'aaa\''
+ read line
+ print $'\'bbb\''
+ read line
+ print $'\'ccc\''
+ read line
+ result=$'\'aaa\'\n\'bbb\'\n\'ccc\''
+ [[ $'\'aaa\'\n\'bbb\'\n\'ccc\'' == 'aaa'$'\n''bbb'$'\n''ccc' ]]
+ echo ok
ok
Users/henk/src/gene-golub$ grep . test/*
test/expected:'aaa'
test/expected:'bbb'
test/expected:'ccc'
test/sample:aaa
test/sample:bbb
test/sample:ccc
/Users/henk/src/gene-golub$
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to