Posts by fedorqui • 265 points
6 posts
-
1
votes1
answer42
viewsA: Can you insert a variable by passing it as a regular expression in the awk command?
you have to use ~, as $0 ~ variable the $1 ~ variable. awk -v patt="Bahia" '$0 ~ patt {print $2}' fichero Example: $ awk -v patt="Bahia" '$1 ~ patt {print $2}' <<< "Bahia blabla" blabla…
-
0
votes1
answer27
viewsA: as it adds a name below a specific search
You can do the following: $ awk '1; /nome2/ {print "teste"}' arquivo.txt nome1 nome2 teste nome3 1; prints all lines. /nome2/ {print "teste"} prints "test" when you find "Nome2".…
-
0
votes1
answer80
viewsA: Condition where you find the name "test" I print OK if NO
In awk: awk '/teste/ {visto=1; exit} END {print visto ? "OK" : "NO"}' arquivo.txt Explanation: /teste/ { cosas } when Awk finds the text "test", it executes the code in {}. visto=1; exit} in this…
-
1
votes1
answer64
viewsA: formatting sql command export with sed
With awk, prints three by three; $ awk 'BEGIN{FS=OFS=";"} {for (i=1; i<NF; i+=3) print $i, $(i+1), $(i+2)}' arquivo "1";"Boi Preto";"2000-02-29" "2";"Sol Nascente";"2009-10-01" "3";"Parque…
-
2
votes1
answer209
viewsA: Doubt with exercise in Shellscript
In the Ex4.1.sh script add the option to enter the word and file name directly from the command line this way: Picks up values with $1, $2...: palavra=$1 arquivo=$2 Thus, $palavra contains the first…
-
3
votes1
answer97
viewsA: Script to swap place string with another string
You cannot change A with B in one step. You need to use a temporary value: A -> XX B -> A XX -> B In this case: sed -e 's/eth0/ethXX/g' -e 's/eth1/eth0/g' -e 's/ethXX/eth1/g' Returns:…