09-15-2010
understanding awk in this script
i am analyzing a query written by another developer ,need to understand part of script
am looking at a code ..and it converts comma files to pipe delimited and also takes away quotes from any columns,
source field format: 2510,"Debbie",NewYork
changes to
target: 2510|Debbie|NewYork
*************Script********
Line 1 cat $out_location/BACI_1000|\
Line 2 awk -v sep=' "" ' \ {
Line 3for (i=1;i<=length($0);i++)
Line 4 {ch=substr($0,i,1)
Line 5if (ch==sep)(inside-!inside}
Line 6if (inside&&ch=="|")
Line 7ch=","
Line 8 printf("%s".ch)
Line 9}
Line 10printf("\n")
Line 11}'>$out_location/aci_10temp
i am not sure why in line 1 is BACI_1000| with a pipe is referred instead of only ACI_1000
line 2 : what is SEP i know IFS is used for field separator ..is it same..also same line why is back slash used before curly brackets
line3:think it searches for lenght of column what does $0 refer here.. i know it refers to command itself in general but not clear
line 4:check for length of column in field 1
line 5:did not understand...(what is inside?)
line 6:did not understand
line 7: did not understand
line 8:does it print the column after removing quotes
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello Friends,
I am new to the scripting & have to analyze bunch of regular production scripts. It has .ksh which calls on the .awk script having many functions
I need to understand and debug the scripts ASAP
Can anybody please let me know as how can I debug, I want to see the flow of code... (3 Replies)
Discussion started by: amberj123
3 Replies
2. Shell Programming and Scripting
Hi Guys,
I was recently come across some code to hopefully learn a little bit about putting Shell commands into PHP application to run on a Linux server. However, I don't understand the command AT ALL... and was wondering if anyone can interpret it:
cat userIDs.dat | awk '{s=s+1; if... (1 Reply)
Discussion started by: jordRiot
1 Replies
3. UNIX for Dummies Questions & Answers
Hi
I have an awk script running in ksh in which a section of code is picking out the datetime as follows:
dia=`echo $starttime | nawk '{ printf "%02d\n", substr($1,9,2)}'`
mes=`echo $starttime | nawk '{ printf "%02d\n", substr($1,6,2)}'`
ano=`echo $starttime | nawk '{ printf "%02d\n",... (3 Replies)
Discussion started by: shajju
3 Replies
4. UNIX for Dummies Questions & Answers
Hey all,
So I have an AWK command here
awk '{if(FNR==NR) {arr++;next} if($0 in arr) { arr--; if (arr == 0) delete arr;next}{print $0 >"list2output.csv"}} END {for(i in arr){print i >"list1output.csv"}}' list1 list2
(refer to image for a more readable format)
This code was submitted... (1 Reply)
Discussion started by: Aussiemick
1 Replies
5. Shell Programming and Scripting
Hi,
Could somebody help me in understanding the following awk expression:
awk -v n="POINT" '/%/{print $0 "\n" n ;next}1' < file name
Thanks,
Arun (6 Replies)
Discussion started by: arun_maffy
6 Replies
6. Shell Programming and Scripting
Hi Experts,
I was looking at the below link, for finding words next to it, And unable to understand this syntax:
Can any one please explain , what is meaning of this code:
if ( F )
s = s ? s OFS $i : $i
from:... (4 Replies)
Discussion started by: rveri
4 Replies
7. UNIX for Dummies Questions & Answers
I found this on an awk site and would like to know what it does:
/CARS/{x="";next} {if(x)print x;x=$0} END{if(x)print x}'
Does it mean if it finds the word cars it skips that line and then prints the next one? (4 Replies)
Discussion started by: newbie2010
4 Replies
8. Shell Programming and Scripting
Hello
I am working on a Change request and Stuck at a point. The below awk command is used in the function.
float_test ( ) {
echo | awk 'END { exit ( !( '"$1"')); }'
}
I understand that awk 'END' is used to add one line at the end and exit is used to end the script with an error... (4 Replies)
Discussion started by: rahul2662
4 Replies
9. Shell Programming and Scripting
Heyas
Recently i wanted to help someone with an awk script, but the end-script didnt work as expected.
He wanted, if HOME was empty, to get the HOME of the current USER from /etc/passwd.
At first i tried hardcoded with root:
awk -F: '/^root/ {print $6}' /etc/passwd
As that worked, i've... (4 Replies)
Discussion started by: sea
4 Replies
10. UNIX for Beginners Questions & Answers
Below script is called as Reducer, I am not sure how it work, can some expert explain me what this script does as i am a beginner.
inputfile:
hi hi how are are you
code:
#!/bin/bash
lastkey=""; -- what does this mean, because i saw in debug mode it is taking value as hi
count=0;... (13 Replies)
Discussion started by: mirwasim
13 Replies
LEARN ABOUT DEBIAN
ttk::spinbox
ttk::spinbox(3tk) Tk Themed Widget ttk::spinbox(3tk)
__________________________________________________________________________________________________________________________________________________
NAME
ttk::spinbox - Selecting text field widget
SYNOPSIS
ttk::spinbox pathName ?options?
_________________________________________________________________
DESCRIPTION
A ttk::spinbox widget is a ttk::entry widget with built-in up and down buttons that are used to either modify a numeric value or to select
among a set of values. The widget implements all the features of the ttk::entry widget including support of the -textvariable option to
link the value displayed by the widget to a Tcl variable.
STANDARD OPTIONS
-class -cursor -style
-takefocus -xscrollcommand
See the ttk_widget manual entry for details on the standard options.
STANDARD OPTIONS
-validate -validatecommand
See the ttk_entry manual entry for details on the standard options.
WIDGET-SPECIFIC OPTIONS
Command-Line Name:-from
Database Name: from
Database Class: From
A floating-point value specifying the lowest value for the spinbox. This is used in conjunction with -to and -increment to set a
numerical range.
Command-Line Name:-to
Database Name: to
Database Class: To
A floating-point value specifying the highest permissible value for the widget. See also -from and -increment. range.
Command-Line Name:-increment
Database Name: increment
Database Class: Increment
A floating-point value specifying the change in value to be applied each time one of the widget spin buttons is pressed. The up but-
ton applies a positive increment, the down button applies a negative increment.
Command-Line Name:-values
Database Name: values
Database Class: Values
This must be a Tcl list of values. If this option is set then this will override any range set using the -from, -to and -increment
options. The widget will instead use the values specified beginning with the first value.
Command-Line Name:-wrap
Database Name: wrap
Database Class: Wrap
Must be a proper boolean value. If on, the spinbox will wrap around the values of data in the widget.
Command-Line Name:-format
Database Name: format
Database Class: Format
Specifies an alternate format to use when setting the string value when using the -from and -to range. This must be a format speci-
fier of the form %<pad>.<pad>f, as it will format a floating-point number.
Command-Line Name:-command
Database Name: command
Database Class: Command
Specifies a Tcl command to be invoked whenever a spinbutton is invoked.
INDICES
See the ttk::entry manual for information about indexing characters.
VALIDATION
See the ttk::entry manual for information about using the -validate and -validatecommand options.
WIDGET COMMAND
The following subcommands are possible for spinbox widgets in addition to the commands described for the ttk::entry widget:
pathName current index
pathName get
Returns the spinbox's current value.
pathName set value
Set the spinbox string to value. If a -format option has been configured then this format will be applied. If formatting fails or is
not set or the -values option has been used then the value is set directly.
SEE ALSO
ttk::widget(3tk), ttk::entry(3tk), spinbox(3tk)
KEYWORDS
entry, spinbox, widget, text field
Tk 8.5.9 ttk::spinbox(3tk)