![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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. |
|
||||
|
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
|
|
||||
|
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.
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|