Tuesday, 4 September 2012

Sed: Insert a string after every line of a file

Input to sed :   

AccessMode.Local
Account
AcquisitionMode
AcquisitionMode.Leased
AcquisitionMode.Loaned
AcquisitionMode.Purchased
AcquisitionMode.Rented
Action


Required Output from sed : 

SELECT 'AccessMode.Local',
UNION ALL
SELECT 'Account',
UNION ALL
SELECT 'AcquisitionMode',
UNION ALL
SELECT 'AcquisitionMode.Leased',
UNION ALL
SELECT 'AcquisitionMode.Loaned',
UNION ALL
SELECT 'AcquisitionMode.Purchased',
UNION ALL
SELECT 'AcquisitionMode.Rented',
UNION ALL
SELECT 'Action',
UNION ALL


Here is the two liner Script:

sed -ne "s/\(.*\)/SELECT '\1',/p" ResourceString.txt  > ResourceString_SELECT.txt
sed -ne "s/$/\nUNION ALL/p" ResourceString_SELECT.txt  > ResourceString_SELECT_UNIONALL.txt   


Reference : http://www.computing.net/answers/unix/how-to-insert-single-quote-in-a-text-line/8570.html 






No comments:

Post a Comment

Tweets by @sriramperumalla