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
concat strings melanie_pfefer Shell Programming and Scripting 1 12-04-2007 07:12 AM
simple question on string concat the_learner High Level Programming 2 08-23-2007 11:09 PM
concat string mpang_ Shell Programming and Scripting 1 07-25-2006 06:03 AM
Concat dhananjaysk Shell Programming and Scripting 1 03-20-2006 07:42 AM
Concat date drukkie UNIX for Dummies Questions & Answers 2 05-30-2002 07:36 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-22-2006
markjason markjason is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 14
concat fields

hi

I have a file, I need to concatenate depening on the no of columns i need to concatenate.
for example i need to concatenate field1,filed34,field2( no of columns is not always 3, it can be any number of fields)
concat.ksh field1 field34 field2

how to achieve this, is there any argv ,argc equivalent in ksh.

Hope i am clear

Mark.
  #2 (permalink)  
Old 10-22-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
You shoud look at the $# and $1, $2,... constructs for ksh. In short $# gives you the number of command line parameters, and $1, $2 gives the parameter1, parameter2. Read man ksh for more details.
  #3 (permalink)  
Old 10-23-2006
napolayan napolayan is offline
Registered User
  
 

Join Date: Oct 2006
Location: Bangalore, India
Posts: 41
just remove the spaces in each line using sed

cat file|while read line
do
sed 's/ //'
done>output_file
  #4 (permalink)  
Old 10-23-2006
markjason markjason is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 14
sorry , i didn't phrase the question correctly.
actually i have those particular fields that needs to be concatenated in a variable.

like this
var1 = 1 24 3

so i need to concatenate these fields, please let me know.

Thanks
Mark.
  #5 (permalink)  
Old 10-23-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
start with awk
Code:
#!/bin/ksh
# $1 $2 $3 equal a field number  eg, 1 7 32
echo "$myvariable" | awk -v one=$1 -v two=$2 -v three=$3 '{ print $one $two $three  }' | read new_variable
# new_variable has the three fields concatenated
  #6 (permalink)  
Old 10-23-2006
markjason markjason is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 14
Jim, this works if we know how many fields we are concatenating.,

in my case, i have n number of fields in the variable that needs to be concatenated.

How can i achieve this. Thanks all for your help.

Last edited by markjason; 10-23-2006 at 11:44 AM..
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:25 PM.


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