Sed appending string using for loop?
Hi All,
I have been trying to format a file using sed. I can't seem to get the syntax right. I want to append the string from file1.txt to file1.csv with the final output file being file2.csv, but before the string is appended to the end of each line, first insert a comma.
Here is the sed command I'm running within the for loop:
for i in `cat file1.txt`
do sed 's/$/,'${i}'/' file1.csv > file2.csv
done
Below is an example of what I'm trying to accomplish:
file1.txt:
r2-1-config
r2-2-config
r2-3-config
r2-4-config
r2-5-config
r2-6-config
r2-7-config
r2-8-config
r2-9-config
r2-10-config
r2-11-config
r2-12-config
r2-13-config
r2-14-config
r2-15-config
r2-16-config
r2-17-config
r2-18-config
r2-19-config
r2-20-config
r2-21-config
r2-22-config
r2-23-config
r2-24-config
r2-25-config
r2-26-config
r2-27-config
r2-28-config
r2-29-config
r2-30-config
file1.csv:
r2-1,r2-ts,2033
r2-2,r2-ts,2034
r2-3,r2-ts,2035
r2-4,r2-ts,2036
r2-5,r2-ts,2037
r2-6,r2-ts,2038
r2-7,r2-ts,2039
r2-8,r2-ts,2040
r2-9,r2-ts,2041
r2-10,r2-ts,2042
r2-11,r2-ts,2043
r2-12,r2-ts,2044
r2-13,r2-ts,2045
r2-14,r2-ts,2046
r2-15,r2-ts,2047
r2-16,r2-ts,2048
r2-17,r2-ts,2049
r2-18,r2-ts,2050
r2-19,r2-ts,2051
r2-20,r2-ts,2052
r2-21,r2-ts,2053
r2-22,r2-ts,2054
r2-23,r2-ts,2055
r2-24,r2-ts,2056
r2-25,r2-ts,2057
r2-26,r2-ts,2058
r2-27,r2-ts,2059
r2-28,r2-ts,2060
r2-29,r2-ts,2061
r2-30,r2-ts,2062
file2.csv:
r2-1,r2-ts,2033,r2-1-config
r2-2,r2-ts,2034,r2-2-config
r2-3,r2-ts,2035,r2-3-config
r2-4,r2-ts,2036,r2-4-config
r2-5,r2-ts,2037,r2-5-config
r2-6,r2-ts,2038,r2-6-config
r2-7,r2-ts,2039,r2-7-config
r2-8,r2-ts,2040.r2-8-config
r2-9,r2-ts,2041,r2-9-config
r2-10,r2-ts,2042,r2-10-config
r2-11,r2-ts,2043,r2-11-config
r2-12,r2-ts,2044,r2-12-config
r2-13,r2-ts,2045,r2-13-config
r2-14,r2-ts,2046,r2-14-config
r2-15,r2-ts,2047,r2-15-config
r2-16,r2-ts,2048,r2-16-config
r2-17,r2-ts,2049,r2-17-config
r2-18,r2-ts,2050,r2-18-config
r2-19,r2-ts,2051,r2-19-config
r2-20,r2-ts,2052,r2-20-config
r2-21,r2-ts,2053,r2-21-config
r2-22,r2-ts,2054,r2-22-config
r2-23,r2-ts,2055,r2-23-config
r2-24,r2-ts,2056,r2-24-config
r2-25,r2-ts,2057,r2-25-config
r2-26,r2-ts,2058,r2-26-config
r2-27,r2-ts,2059,r2-27-config
r2-28,r2-ts,2060,r2-28-config
r2-29,r2-ts,2061,r2-29-config
r2-30,r2-ts,2062,r2-30-config
Last edited by cstovall; 01-28-2007 at 07:22 PM..