Sponsored Content
Full Discussion: awk print in script
Top Forums Shell Programming and Scripting awk print in script Post 302976068 by ocbit on Thursday 23rd of June 2016 09:23:11 AM
Old 06-23-2016
The code I provided works perfectly fine as I posted it. Why would I post it and say it works if it doesn't? Replacing <machine> data is my addition to it, but that is not relevant to this post.

The original code is:

Code:
awk '
FNR == NR       {sub (/\./, "/", $1)
                 T[$1] = $2
                 next
                }
                {for (t in T) if ($0 ~ t) TF = t
                }
TF && /<value/  {sub (/>[^<]*</, ">" T[TF] "<")
                 TF = ""
                }
1
' FS="~" flatfile xmlfile

Currently, the code takes a text input file with format
Code:
Application.Env~DEV 
Application.ID~99999
Application.Name~appname

along with an XML input file with format
Code:
<name>Application/Env</name> 
<value>TST</value> 
<name>Application/ID</name> 
<value>00000</value>
<name>Application/Name</name> 
<value>Name</value>

and replaces <value> data with the data found after the ~ in the text file.
So afterwards it looks like
Code:
<name>Application/Env</name> 
<value>DEV</value> 
<name>Application/ID</name> 
<value>99999</value>
<name>Application/Name</name> 
<value>appname</value>

What I'm now asking is - Where would I put print commands in this script to show on the command line what is being replaced line by line?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK script to print all the columns excpet the one specified

I have several columns by the name A B C D E...... and I want to print all the column other than column C and D. Could you please help me with the awk script? Thanks!! (3 Replies)
Discussion started by: kn.naresh
3 Replies

2. Shell Programming and Scripting

awk/shell script to print each line to a file

Dear People, My query is: have a file, which looks likes this: 10 20 30 40 50 1 2 3 4 5 100 200 300 400 500 what i need is: "PRINT EACH LINE TO AN UNIQUE FILE" desired output: file 1 10 20 30 40 50 file 2 1 2 3 4 5 (3 Replies)
Discussion started by: saint2006
3 Replies

3. Shell Programming and Scripting

awk script: print line number n of another file

Hi, I wrote an awk script to analyse file A. I call the script with files A and B. File A has lines like: 000000033100001 000000036100001 000000039100001 The first 9 characters are interpreted as a line number; for each line number found I want to output this line number of file B. ... (13 Replies)
Discussion started by: kpg
13 Replies

4. Shell Programming and Scripting

AWK Script - Print a column - within a Row Range

Hi, Please read the whole thread. I have been working on this script below. It works fine, feel free to copy and test with the INPUT File below as well. example: PACKET DATA PROTOCOL CONTEXT DATA APNID PDPADD EQOSID VPAA PDPCH PDPTY PDPID 10 ... (6 Replies)
Discussion started by: panapty
6 Replies

5. Shell Programming and Scripting

How to print backslash in shell script using awk?

I found that echo "aaa" | awk '{print ",\\";}' works, and it will give "\". but ddd=`echo "aaa" | awk '{print ",\\";}'`; echo $ddd will not work. Could anyone tell me why? thank you. (8 Replies)
Discussion started by: wxuyec
8 Replies

6. Fedora

Shell Script - awk, begin, for and print

pointsb=`awk -v a2="$a2" -v b2="$b2" -v c2="$c2" -v yb="$yb" -v yc="$yc" \ 'BEGIN { for (y=yc; y<=yb; y++) { x = a2*y*y+b2*y+c2; print x, y }; }'` I am learning shell script. I was reading a script and got confused in this line. I understood that awk is allowing to assign the variable. But... (10 Replies)
Discussion started by: agriz
10 Replies

7. Shell Programming and Scripting

awk script to search output for a value and print

GOODNUMBERS="1 2 3 4 5 6 3 3 34 34 5 66 12" BADNUMBERS="7 3 12 5 66" for eachnum in `echo ${GOODNUMBERS}` do echo ${BADNUMBERS} | gawk -v threshold=${eachnum} '$1 != threshold' done what im trying to do with the above is, i want to print numbers that are in the GOODNUMBERS... (10 Replies)
Discussion started by: SkySmart
10 Replies

8. Shell Programming and Scripting

awk script to match and print

I need a script that will search for a string from column 1 in file A and when the string matches the last column in file B, print columns 1, 2 (file A) and columns 2, 3 (file B). input file A stringtomatch1 a stringtomatch2 a stringtomatch3 b file B junkcolumn1 printcolumn2... (4 Replies)
Discussion started by: ncwxpanther
4 Replies

9. Shell Programming and Scripting

awk script to print file name

I have the following awk script that looks at the first 2 columns of multiple files and when they match, it prints the min of the 3rd column. for year in tave-{1950..2015}.txt do cat "$year" done | awk '{n=$3; $3=x} !($0 in A) || n<A {A=n} END{for(i in A) print i A}' > output.txt ... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

10. UNIX for Beginners Questions & Answers

awk script to match string and print status

Dear team, Need support to built awk script for below requirement Input file LOTC cluster state: ------------------- Node safNode=SC_2_1 joined cluster | Node safNode=SC_2_2 joined cluster | Node safNode=PL_2_3 fail cluster | AMF cluster state: ------------------... (16 Replies)
Discussion started by: shanul karim
16 Replies
post(3FORM)															       post(3FORM)

NAME
post - write or erase forms from associated subwindows SYNOPSIS
#include <form.h> int post_form(FORM *form); int unpost_form(FORM *form); DESCRIPTION
The function post_form displays a form to its associated subwindow. To trigger physical display of the subwindow, use refresh or some equivalent curses routine (the implicit doupdate triggered by an curses input request will do). The function unpost_form erases form from its associated subwindow. RETURN VALUE
These routines return one of the following: E_OK The routine succeeded. E_BAD_ARGUMENT Routine detected an incorrect or out-of-range argument. E_BAD_STATE Routine was called from an initialization or termination function. E_NOT_POSTED The form has not been posted. E_NOT_CONNECTED No items are connected to the form. E_NO_ROOM Form is too large for its window. E_POSTED The form has already been posted. E_SYSTEM_ERROR System error occurred (see errno). SEE ALSO
ncurses(3NCURSES), form(3FORM). NOTES
The header file <form.h> automatically includes the header file <curses.h>. PORTABILITY
These routines emulate the System V forms library. They were not supported on Version 7 or BSD versions. AUTHORS
Juergen Pfeifer. Manual pages and adaptation for new curses by Eric S. Raymond. post(3FORM)
All times are GMT -4. The time now is 11:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy