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
Concatenating records from 2 files Powcmptr UNIX for Dummies Questions & Answers 4 04-02-2008 03:57 PM
Count No of Records in File without counting Header and Trailer Records guiguy Shell Programming and Scripting 2 06-07-2007 12:15 PM
concatenating string and variable rolex.mp UNIX for Dummies Questions & Answers 1 02-14-2007 11:17 AM
finding null records in data file dsravan Shell Programming and Scripting 3 01-09-2007 03:46 PM
How to make static unicode string? sledge76 High Level Programming 1 01-19-2005 06:44 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 06-20-2006
gillbates gillbates is offline
Registered User
  
 

Join Date: Mar 2002
Location: DC
Posts: 46
concatenating static string to records in data file

I just need to add a static ID to each output record so the users will be able to tell which group records in combined flatfiles come from I have the static ID in a bourne variable. I tried

awk '{print "${GroupID}" $0}' infile > outfile

But I ended up with the string ${GroupID} instead of the value of the var in the output file. Surely there's an easy way to do this? Thanks.
  #2 (permalink)  
Old 06-20-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
sed "s#^#${GroupID} #" infile > outfile
  #3 (permalink)  
Old 06-22-2006
thestevew thestevew is offline
Registered User
  
 

Join Date: Mar 2006
Location: South Yorkshire, UK
Posts: 114
You can pass variables into Awk using -v (and note that they are printed without the leading $)
Code:
$ GroupID="This Group"
$ awk -v GID="$GroupID " '{print GID $0}'  names.dat
This Group Jim
This Group Jon
This Group Joe
  #4 (permalink)  
Old 06-22-2006
gillbates gillbates is offline
Registered User
  
 

Join Date: Mar 2002
Location: DC
Posts: 46
This works but I don't understand what the #s do. Do they substitute for a slash in sed? Oh, and thanks for the help. I got snowed with other issues for a couple of days so I was just able to impliment this.
  #5 (permalink)  
Old 06-22-2006
gillbates gillbates is offline
Registered User
  
 

Join Date: Mar 2002
Location: DC
Posts: 46
I had vgersh99's response open on one of my monitors since yesterday so I hadn't noticed thestevew's response. While thestevew's response looks good and would undoubtably work it's not near as obscure as vgersh99's response. So in the old unix spirit I'll go with that.
  #6 (permalink)  
Old 06-22-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by gillbates
This works but I don't understand what the #s do. Do they substitute for a slash in sed? Oh, and thanks for the help. I got snowed with other issues for a couple of days so I was just able to impliment this.
Yes, that's correct - you can use ANY single character as an 'action' separator in sed. The more common and widely spread is ''/
Sponsored Links
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 02:12 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