fishScript.com d
Home| Progetto| Web| Faq| Acronimi

Argomenti







PLSQL... Script: Cursore implicito SQL

Shell scripting... Script: Looping samples

Un servizio Web XML è un'unità logica di applicazioni che fornisce dati e servizi ad altre applicazioni. Le applicazioni accedono ai servizi Web XML tramite protocolli Web universali e formati di dati quali HTTP, XML e SOAP.



La J2EE (Java 2 Enterprise Edition) è dedicata a tutti coloro che desiderano aggiungere il supporto della versione Enterprise di Java (ad esempio a Tomcat) e quindi le funzionalità avanzate come Enterprise JavaBeans etc.

Un servizio Web XML è un'unità logica di applicazioni che fornisce dati e servizi ad altre applicazioni. Le applicazioni accedono ai servizi Web XML tramite protocolli Web universali e formati di dati quali HTTP, XML e SOAP.

Unix

Home >Unix > awk command line tutorial and examples

Stampa  Stampa


Some notes and examples on awk program tested on UNIX HP-UX fxsvil04 B.11.23 U ia64.

 
# begin printing text # \n stands for new line server01:/# awk 'BEGIN { print " one \n two\n three" }' one two three
# \t stands for tab awk 'BEGIN { print "one\t two \tthree" }' one two three # use following syntax to print single quote(1) server01:/#awk 'BEGIN { print "Print single quote: \t '\'' " }' Print single quote: ' # in alternative, use following syntax to print single quote(1) alternative server01:/#awk "BEGIN { print \" Print single quote: \t ' \" }" Print single quote: ' # print double quotes \42 (1) server01:/#awk 'BEGIN { print "Print double quote: \42" }' Print double quote: " # print double quotes (2) alternative, declaring it first. server01:/#awk -v db="\"" 'BEGIN { print "Here is a single quote " db " " }' # formatting output server01:/#ls -la | awk 'BEGIN { print "File\tOwner\tBytes" } { print $9, "\t", $3 "\t", $5 } END { print " - DONE -" } '
File Owner Bytes ./ bin 8192 ../ root 8192 backup/ root 8192 boot.sys/ bin 96 bootconf root 21 bootfs@ root 14 current/ root 8192 ioconfig root 3804 kernrel root 82 krs/ root 96
# loop basic example server01:/# awk 'BEGIN { for (i=1; i <= 5; i++) {print "The square of " i " is " i*i ;} } '
The square of 1 is 1 The square of 2 is 4 The square of 3 is 9 The square of 4 is 16 The square of 5 is 25
# working with text files # text file example "testfile.txt" # columns (or fields) are separated by blank
ITALY ROME PARIOLI ITALY MILAN FRANCE PARIS FRANCE LION ITALY ROME ALBERONE ITALY PALERMO BRANCACCIO SPAIN MADRID USA NY QUEEN ASTORIA PORTUGAL LISBON
# print fields (1) # $0 to print all text file row server01:/#awk '{print $0}' testfile.txt
ITALY ROME PARIOLI ITALY MILAN FRANCE PARIS FRANCE LION ITALY ROME ALBERONE ITALY PALERMO BRANCACCIO SPAIN MADRID USA NY QUEEN ASTORIA PORTUGAL LISBON
# print fields (2) # first e third column and using string converting case tolower or toupper server01:/#awk ' {print $1 , tolower($3)} ' testfile.txt
ITALY parioli ITALY FRANCE FRANCE ITALY alberone ITALY brancaccio SPAIN USA queen PORTUGAL
# managing fields, NF identify their number server01:/#awk '{print $0 , "Number field:\t" NF }' testfile.txt
ITALY ROME PARIOLI Number field: 3 ITALY MILAN Number field: 2 FRANCE PARIS Number field: 2 FRANCE LION Number field: 2 ITALY ROME ALBERONE Number field: 3 ITALY PALERMO BRANCACCIO Number field: 3 SPAIN MADRID Number field: 2 USA NY QUEEN ASTORIA Number field: 4 PORTUGAL LISBON Number field: 2
# columns separated by chars # columns separated by : in file cityresidents.txt:
Firenze:979945 Bologna:968400 Padova:913174 Verona:899603 Caserta:899248 Genova:883913 Firenze:979945 Bologna:968400 Padova:913174 Verona:899603 Caserta:899248 Genova:883913
# if fields are non separated spaces but by some chars, –F to define separation server01:/#awk -F":" '{print "City: " $1 "\t Residents: " $2}' cityresidents.txt
City: Firenze Residents: 979945 City: Bologna Residents: 968400 City: Padova Residents: 913174 City: Verona Residents: 899603 City: Caserta Residents: 899248 City: Genova Residents: 883913 City: Firenze Residents: 979945 City: Bologna Residents: 968400 City: Padova Residents: 913174 City: Verona Residents: 899603 City: Caserta Residents: 899248 City: Genova Residents: 883913
# NRidentify row number in text file server01:/#awk '{ print "ROW: "NR "\t" $0}' testfile.txt
ROW: 1 ITALY ROME PARIOLI ROW: 2 ITALY MILAN ROW: 3 FRANCE PARIS ROW: 4 FRANCE LION ROW: 5 ITALY ROME ALBERONE ROW: 6 ITALY PALERMO BRANCACCIO ROW: 7 SPAIN MADRID ROW: 8 USA NY QUEEN ASTORIA ROW: 9 PORTUGAL LISBON
# use sort -u command to eliminate duplicate rows server01:/#awk ' {print $1 , tolower($3)} ' testfile.txt |sort -u
FRANCE ITALY ITALY alberone ITALY brancaccio ITALY parioli PORTUGAL SPAIN
# adding and encapsuling chars to field server01:/#awk '{ printf("*%s (%s)\n", tolower($2), toupper($1)) }' testfile.txt
*rome (ITALY) *milan (ITALY) *paris (FRANCE) *lion (FRANCE) *rome (ITALY) *palermo (ITALY) *madrid (SPAIN) *ny (USA) *lisbon (PORTUGAL)
# if, conditional (1) # if first field equals to ITALY print line server01:/#awk ' ($1=="ITALY") {print $0}' testfile.txt
ITALY ROME PARIOLI ITALY MILAN ITALY ROME ALBERONE ITALY PALERMO BRANCACCIO
# if, conditional (2) # use of match if first field contains (match) IT print row server01:/#awk 'match($1,"IT") {print $0}' testfile.txt
ITALY ROME PARIOLI ITALY MILAN ITALY ROME ALBERONE ITALY PALERMO BRANCACCIO
# if, conditional (3) compact construct, if row contains "ROME" print it server01:/#awk '$0 ~ /ROME/ {print $0}' testfile.txt
ITALY ROME PARIOLI ITALY ROME ALBERONE
#extract, using substr, chars from String by position, in the example from 1 to 2 position of first column server01:/#awk '{ print substr($1,1,2)}' testfile.txt
IT IT FR FR IT IT SP US PO
# function index(s1,s2) returns position of parameter in the string server01:/#awk '{ print index($0,"ROME")}' testfile.txt
7 0 0 0 7 0 0 0 0
# function length returs string length server01:/#awk '{ print "Row:" NR "\t" "Field string: " $2 "\t" "String length: " length($2)}' testfile.txt
Row:1 Field string: ROME String length: 4 Row:2 Field string: MILAN String length: 5 Row:3 Field string: PARIS String length: 5 Row:4 Field string: LION String length: 4 Row:5 Field string: ROME String length: 4 Row:6 Field string: PALERMO String length: 7 Row:7 Field string: MADRID String length: 6 Row:8 Field string: NY String length: 2 Row:9 Field string: LISBON String length: 6
#length conditional construct. If field 2 is more the 5 chars, print it server01:/#awk '(length($2)>5) {print $2}' testfile.txt
PALERMO MADRID LISBON

Exampls by dott. Marco Magnani dba



Tutorial
Executing a shell script  [Unix] 
Shell scripting passare parametri ad un programma [Shell scripting] 
Cheking mandatory parameters have been passed to shell file, comparing strings in if construct and some other basics warming up with shell scripting [Shell scripting] 
Estendere un logical volume e di un filesystem allocare più storage da riga di comando su Unix Hp [HP UX 11i] 
Korn shell scripting If constructs AND, OR, &&, || syntax examples [Unix] 
Function connecting to oracle getting results, executing query, verify db connection [Shell scripting] 
Cheking parameters have been passed to shell file, comparing strings in if construct warming up with shell scripting [Shell scripting] 
awk command line tutorial and examples sintax, functions, conditional constructs, text file operations [Unix] 
How many processor and what kind of CPU extracting info from red hat system file /proc/cpuinfo [REDHAT] 
sed command example on fixing errors and adding and removing blank lines [Unix] 
Shell scripting eseguire controlli  [Shell scripting] 
Script
while do loop simple shell script [Shell scripting] 
if e else strutture condizionali [Shell scripting] 
Array valorizzazione e stampa [Shell scripting] 
Hide user input on screen parameter of read command [Shell scripting] 
Array in do while construct printing elements [Shell scripting] 
Shell script automating oracle data pump schema export automatically export and compress database schemas in single separated dump files [Shell scripting] 
Script per ricavare i nomi dei db (SID) dal file oratab  [Unix] 
Ciclo sul contenuto directory  [Shell scripting] 
If contruct check if a value is null or not [Unix] 
Shell script extract items and looping example: issue dba statment for each db listed in oratab [Unix] 
Passing parameters to shell script example sum of two numbers [Shell scripting] 
Export and compress dump on the fly script to reduce storage need while using exp and imp Oracle utilities [Unix] 
Pulire i file provenienti da ambieti dos/ windoes da caratteri sporchi dos2ux, dos2unix per eliminare i control M (^M) [Shell scripting] 
Script for archiving and compressing folder and file utility example [Shell scripting] 
How to get size or other file info in a shell script manipulating with cut or awk operative system commands output [Shell scripting] 
Comandi
Privilegi su file o cartella (lettura, scrittura, execuzione)  [Unix] 
Cancellazione di una directory rm o rmdir  [Unix] 
Cd: cambiare directory  [Unix] 
Copiare un file in un altra cartella  [Unix] 
hostname  [HP UX 11i] 
uname visaulizza informazioni sul sistema operativo e la versione [HP UX 11i] 
ipcs report stato dei processi [HP UX 11i] 
getconf ricavare se si ha a disposizione un Kernel da 32-bit o 64-bit  [HP UX 11i] 
swlist -l patch determinare il software e le patch installate nella piattaforma [HP UX 11i] 
who determinare gli utenti connessi [Unix] 
shutdown  [Unix] 
env visualizzazione (e modifica) variabili dell'ambiente  [Unix] 
w attività degli utenti [Unix] 
bdf visualizzare spazio disponibile [HP UX 11i] 
df visualizzazione spazio disponibile [Unix] 

signal Marco Magnani marcomagnani@fishscript.com



Cerca




Unix... Info: ps

Well-formedness is a new concept introduced by [XML]. Essentially this means that all elements must either have closing tags or be written in a special form (as described below), and that all the elements must nest properly.


Well-formedness is a new concept introduced by [XML]. Essentially this means that all elements must either have closing tags or be written in a special form (as described below), and that all the elements must nest properly.




Oracle... Definizioni: SESSION





fishScript.Com is accessible by Mobile access technology as mobile phones, Palm and Pocket PC .

Nicoleta e Marco Magnani tutorial, examples, courses, esempi, corsi, esercizi, appunti vari Dottoressa Nicoleta Dragu Formatrice Docente Insegnante Mediatrice Culturale Dott. Marco Magnani Universita La Sapienza Roma Master Computer Science Hunter College New York , Data Base Administrator DBA oracle System architect

Last modified: 2017-11-30 amministratore@fishscript.comNico and Marco Magnani Software Production
Home|About this Site © 2003-2008 www.fishScript.com ®