UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old November 19th, 2004, 05:04 AM
fkouk fkouk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 3 fkouk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
replacement cmd?

I have a file with three Columns (Id, First Name, Last Name) and a file that have one line as follows:
Id, other strings, First Name, Last Name, other strings
I want to create a new file that will replace Id, First Name, Last Name of the second file with all corresponding lines of the first file. In that sense the new file will have the same number of lines with the first one. Awk does not work since the strings that exist as default in the second file are quiet long and I got the following error:
awk: string too long near line 1

Any idea if there is any other way?

thank you

Reply With Quote
  #2  
Old November 19th, 2004, 06:09 AM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
Can you give examples of the file you've got and the result you want to end up with?

Reply With Quote
  #3  
Old November 19th, 2004, 07:10 AM
fkouk fkouk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 3 fkouk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by andyb1ack
Can you give examples of the file you've got and the result you want to end up with?

Ok, I have a file with 3 columns
1,444666999,999888999000
2,777888999,888333999888
3,222888991,333222111000
etc

and I want to produce the following file:

1A444666999BN999888999000end
2A777888999BN888333999888end
3A222888991BN333222111000end
etc
Column 1 appears before A, column B appears after A and column C appears after BN. This is a pure example. In fact strings A, CB and end are too long and for that I cannot use awk to print them.
Best Regards,

Reply With Quote
  #4  
Old November 19th, 2004, 08:51 AM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
This should help:

cat /var/tmp/asb
1,444666999,999888999000
2,777888999,888333999888
3,222888991,333222111000


string1=hello
string2=bye
string3=end


sed "s/\(.*\),\(.*\),\(.*\)/\1${string1}\2${string2}\3${string3}/" /var/tmp/asb
1hello444666999bye999888999000end
2hello777888999bye888333999888end
3hello222888991bye333222111000end

Reply With Quote
  #5  
Old November 24th, 2004, 09:53 AM
fkouk fkouk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 3 fkouk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by andyb1ack
This should help:

cat /var/tmp/asb
1,444666999,999888999000
2,777888999,888333999888
3,222888991,333222111000


string1=hello
string2=bye
string3=end


sed "s/\(.*\),\(.*\),\(.*\)/\1${string1}\2${string2}\3${string3}/" /var/tmp/asb
1hello444666999bye999888999000end
2hello777888999bye888333999888end
3hello222888991bye333222111000end


ok, thanks.

Reply With Quote
  #6  
Old November 25th, 2004, 08:54 PM
vvenkatkalpana vvenkatkalpana is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 2 vvenkatkalpana User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
try this

Hi
just try this
sed "s/\(.*\),\(.*\),\(.*\)/\1FIRSTSUBSTITUTION\2SECONDSUBST\3THIRDSUBST/" filename

{pls note that the command should be on single line

let me know how it works!

regards
kalpana

Quote:
Originally Posted by fkouk
Ok, I have a file with 3 columns
1,444666999,999888999000
2,777888999,888333999888
3,222888991,333222111000
etc

and I want to produce the following file:

1A444666999BN999888999000end
2A777888999BN888333999888end
3A222888991BN333222111000end
etc
Column 1 appears before A, column B appears after A and column C appears after BN. This is a pure example. In fact strings A, CB and end are too long and for that I cannot use awk to print them.
Best Regards,

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > replacement cmd?


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway