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
simple shell - how to get a parameter typed in a shell script cmitulescu Shell Programming and Scripting 4 01-09-2009 08:45 PM
Simple Shell Script Need Help kulbir Shell Programming and Scripting 2 02-27-2008 01:14 AM
what's the largest shell script you've ever written? OFFSIHR Shell Programming and Scripting 2 04-26-2007 10:54 AM
need a simple shell script Mar1006 Shell Programming and Scripting 1 08-01-2006 10:45 AM
Simple shell script to be written shsandeep UNIX for Dummies Questions & Answers 2 07-17-2006 01:19 AM

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 07-17-2006
shsandeep shsandeep is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 5
Simple shell script to be written

There are 2 shell script files sh1 and sh2.
sh2 contains records such as 01 02 03 on different lines.
In sh1, I would like to read each record of sh2 till end of file, concatenate them with a comma(,) and store in a variable.

Can somebody please help me with the sh1 script?
Thanks in advance.

Cheers,
San.
  #2 (permalink)  
Old 07-17-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Can you post some sample data and also what you have coded till now?
  #3 (permalink)  
Old 07-17-2006
shsandeep shsandeep is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 5
Sample data

I am a newbie to shell scripting, so have not started anything....
Here is what sh2 will have:
01
02
03
04
05

In sh1, I would like to have a variable 'str' to have '01,02,03,04,05' in it.

Thanks for replying...

Cheers,
San.
  #4 (permalink)  
Old 07-17-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Code:
#! /bin/sh
str=`cat sh2`
echo $str
  #5 (permalink)  
Old 07-17-2006
shsandeep shsandeep is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 5
Re:

Thanks for the solution...
However, I need a comma separator in between as well.
Current solution: '01 02 03'
Required: '01,02,03'

Cheers,
San.
  #6 (permalink)  
Old 07-17-2006
manthasirisha manthasirisha is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 59
shsandeep,

Just substitute the " "(white space with commas) as below:

echo $str | sed 's/ /,/g'

Hereon, it'd be good if u can post ur work before asking for ready help!
Goodluck!
  #7 (permalink)  
Old 07-17-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by shsandeep
I am a newbie to shell scripting, so have not started anything....
Here is what sh2 will have:
01
02
03
04
05

In sh1, I would like to have a variable 'str' to have '01,02,03,04,05' in it.

Thanks for replying...

Cheers,
San.
Code:
echo "01
02
03
04
05" | tr  "\n" ","
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 07:29 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