![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
sed "s#^#${GroupID} #" infile > outfile
|
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
Quote:
|
||||
| Google The UNIX and Linux Forums |