The UNIX and Linux Forums  

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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-20-2006
Registered User
 

Join Date: Mar 2002
Location: DC
Posts: 41
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.
Reply With Quote
Forum Sponsor
  #2  
Old 06-20-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,016
sed "s#^#${GroupID} #" infile > outfile
Reply With Quote
  #3  
Old 06-22-2006
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
Reply With Quote
  #4  
Old 06-22-2006
Registered User
 

Join Date: Mar 2002
Location: DC
Posts: 41
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.
Reply With Quote
  #5  
Old 06-22-2006
Registered User
 

Join Date: Mar 2002
Location: DC
Posts: 41
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.
Reply With Quote
  #6  
Old 06-22-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,016
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 ''/
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0