The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Appending 'string' to file as first column. satyam_sat Shell Programming and Scripting 6 02-20-2009 05:15 AM
appending two string is not working krishna9 Shell Programming and Scripting 11 05-19-2008 04:31 AM
Appending a string to all files in a directory ragavhere Shell Programming and Scripting 1 04-28-2008 06:31 AM
appending string to text file based on search string malaymaru Shell Programming and Scripting 1 06-09-2006 08:53 AM
Appending to filename a string of text grep finds HLee1981 Shell Programming and Scripting 3 09-06-2005 02:44 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-28-2007
cstovall cstovall is offline
Registered User
  
 

Join Date: Nov 2002
Location: Raleigh, N.C.
Posts: 78
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..
  #2 (permalink)  
Old 01-28-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Try...
Code:
paste -d, file1.csv file1.txt > file2.csv
  #3 (permalink)  
Old 01-28-2007
cstovall cstovall is offline
Registered User
  
 

Join Date: Nov 2002
Location: Raleigh, N.C.
Posts: 78
Thank you Ygor! The paste command and delimiter flag worked.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0