0

If I have a list of data in a text file seperated by a new line, is there a way to append something to the start, then the data, then append something else then the data again?

EG a field X would become new X = X;

Can you do this with bash or sed or just unix tools like cut?

EDIT:

I am trying to get "ITEM_SITE_ID :{$row['ITEM_SITE_ID']}
" .

I am using this line awk '{ print "\""$1 " {:$row['$1']}
" }'

And I get this "ITEM_SITE_ID {:$row[]}

What have I missed?

4

2 回答 2

1

Awk is often the perfect tool for tasks like this. For your specific example:

awk '{ print "new " $1 " = " $1 ";" }'
于 2008-10-30T14:34:04.613 回答
1

I think the problem is your single quotes are not properly escaped, which is actually impossible to do.

With sed:

sed "s/\(.*\)/\1 = \1;/"

Or in your case:

sed "s/\(.*\)/\"\1 :{\$row['\1']}\"/"

And with bash:

while read line
do
    echo "\"$line :{\$row['$line']}\""
done

And actually you can do it in awk using bashes $'' strings:

awk $'{ print "\\"" $1 " :{$row[\'" $1 "\']}\\"" }'
于 2008-10-30T14:48:09.687 回答