Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Just want to ask if there is a shorter hand to doing this one liner Post 303030907 by stomp on Tuesday 19th of February 2019 03:55:58 AM
Old 02-19-2019
This is possible within a single awk call:

program.awk
Code:
 (FNR == NR && NR > 2) {
        headers[NR-2]=$1
}

(FNR != NR) {
        if(FNR == 1) {
           printf "%-30s|%-30s|%-15s\n",headers[1],headers[2],headers[3]
        }
        print
}

Call it like an external program like this: awk -f program.awk header.txt data.txt or inline as ...
Code:
awk '(FNR==NR && NR > 2) { h[NR-2]=$1 } (FNR!=NR) { if(FNR==1) { printf "%-30s|%-30s|%-15s\n",h[1],h[2],h[3] } print }' header.txt data.txt


Last edited by stomp; 02-19-2019 at 05:25 AM..
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Give us a hand

How do you get an awk output into columns i.e. awk (print $1,$2,$3) doesn't come out into nice columns but lots of lines of txt want something more like. I am crap at unix so give me a hand thx Rich (3 Replies)
Discussion started by: RichardB
3 Replies

2. Shell Programming and Scripting

How to get the most left hand string ??

Hi, I remember once seeing a way to get the left most string in a word. Let's say: a="First.Second.Third" (separated by dot) echo ${a#*.} shows --> Second.Third echo ${a##*.} shows --> Third How do I get the the left most string "First" Or "First.Second" ??? Tried to replace #... (2 Replies)
Discussion started by: jfortes
2 Replies

3. Shell Programming and Scripting

Need a hand. Please?

i have a script in sh. with awk, e.g. want to list all the contents of a subdirectory an a tabular way. ej: outoput directory1 subdirectory1 subdirectory2 subdirectory3 file1 filen file2 filez file2 ... filen+1 ... (1 Reply)
Discussion started by: alexcol
1 Replies

4. Debian

change initramfs by hand?

What's the correct way to change the initramfs file that's used during boot? I know that it's a gzipped cpio archive, but when I gunzip, extract, re-archive (without changing any files), and gzip, then the result is that the system does not boot any more. And I even set the cpio archive type. ... (18 Replies)
Discussion started by: frankie06
18 Replies

5. UNIX for Dummies Questions & Answers

Shorter AWK for my code?

Hi Folks, I know my code works, but I'm still a newbie at arrays and how they function. Is there is shorter way to write my code? I'm taking averages in multiple files and concatenating output into 1 file. TIA! for file in *; do awk -F"\t" '{a1+=$1}{a2+=$2}{a3+=$3} {a4+=$4}{a5+=$5}... (1 Reply)
Discussion started by: calitiggr
1 Replies

6. Shell Programming and Scripting

Deleting shorter lines from data file

Hello, I have the following data file structure: 1234 text 2345 text 3456 text text text 4567 text text text 5678 text text text 6789 text text text I simply want to delete all of the lines that only have one text column (i.e. the first two lines in this case). The output would be:... (1 Reply)
Discussion started by: palex
1 Replies

7. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

8. Shell Programming and Scripting

Combine columns from many files but keep them aligned in columns-shorter left column issue

Hello everyone, I searched the forum looking for answers to this but I could not pinpoint exactly what I need as I keep having trouble. I have many files each having two columns and hundreds of rows. first column is a string (can have many words) and the second column is a number.The files are... (5 Replies)
Discussion started by: isildur1234
5 Replies

9. Shell Programming and Scripting

Merge left hand strings mapping to different right hand strings

Hello, I am working on an Urdu to Hindi dictionary which has the following structure: a=b a=c n=d n=q and so on. i.e. Headword separated from gloss by a = I am giving below a live sample بتا=बता بتا=बित्ता بتا=बुत्ता بتان=बतान بتان=बितान بتانا=बिताना I need the following... (3 Replies)
Discussion started by: gimley
3 Replies
SQL::Translator::Producer::Oracle(3pm)			User Contributed Perl Documentation		    SQL::Translator::Producer::Oracle(3pm)

NAME
SQL::Translator::Producer::Oracle - Oracle SQL producer SYNOPSIS
use SQL::Translator; my $t = SQL::Translator->new( parser => '...', producer => 'Oracle' ); print $translator->translate( $file ); DESCRIPTION
Creates an SQL DDL suitable for Oracle. producer_args delay_constraints This option remove the primary key and other key constraints from the CREATE TABLE statement and adds ALTER TABLEs at the end with it. quote_field_names Controls whether quotes are being used around column names in generated DDL. quote_table_names Controls whether quotes are being used around table, sequence and trigger names in generated DDL. NOTES
Autoincremental primary keys This producer uses sequences and triggers to autoincrement primary key columns, if necessary. SQLPlus and DBI expect a slightly different syntax of CREATE TRIGGER statement. You might have noticed that this producer returns a scalar containing all statements concatenated by newlines or an array of single statements depending on the context (scalar, array) it has been called in. SQLPlus expects following trigger syntax: CREATE OR REPLACE TRIGGER ai_person_id BEFORE INSERT ON person FOR EACH ROW WHEN ( new.id IS NULL OR new.id = 0 ) BEGIN SELECT sq_person_id.nextval INTO :new.id FROM dual; END; / Whereas if you want to create the same trigger using "do" in DBI, you need to omit the last slash: my $dbh = DBI->connect('dbi:Oracle:mysid', 'scott', 'tiger'); $dbh->do(" CREATE OR REPLACE TRIGGER ai_person_id BEFORE INSERT ON person FOR EACH ROW WHEN ( new.id IS NULL OR new.id = 0 ) BEGIN SELECT sq_person_id.nextval INTO :new.id FROM dual; END; "); If you call this producer in array context, we expect you want to process the returned array of statements using DBI like "deploy" in DBIx::Class::Schema does. To get this working we removed the slash in those statements in version 0.09002 of SQL::Translator when called in array context. In scalar context the slash will be still there to ensure compatibility with SQLPlus. CREDITS
Mad props to Tim Bunce for much of the logic stolen from his "mysql2ora" script. AUTHORS
Ken Youens-Clark <kclark@cpan.org>, Alexander Hartmaier <abraxxa@cpan.org>, Fabien Wernli <faxmodem@cpan.org>. SEE ALSO
SQL::Translator, DDL::Oracle, mysql2ora. perl v5.14.2 2012-01-18 SQL::Translator::Producer::Oracle(3pm)
All times are GMT -4. The time now is 09:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy