A more cryptic solution using sed :
sed -n 'H;${x;s/\n//g;s/,$//;p;}'dftmp2
For a production script, prefer the PHV'solution that is more simple to understand and to maintain.
Jean-Pierre.
GNU sed
The following address types are supported:
number Match only the specified line number.
first~step
Match every step'th line starting with line first. For example, ``sed -n
1~2p'' will print all the odd-numbered lines in the input stream, and the
address 2~5...
Another syntax :
integer CurrentBackup PreviousBackup CurrentNumber
if ((CurrentBackup==0)); then
(( PreviousBackup=10-(CurrentNumber-1) ))
else
(( PreviousBackup=CurrentNumber-1 ))
fi
Jean-Pierre.
A small variation :
- Use any non alpha-numeric character as field separator.
- Strings are displayed only once.
awk -F '[^[:alnum:]]' '
{
for (f=1; f<=NF; f++) {
if ($f ~ /GN0[0-9][0-9][0-9][0-9]/)
++strings[substr($f, 1, 7)];
}
}
END {
for (s in...
You can include the awk program in a ksh script in the following ways :
1) Create the awk program file fmt.awk and include the following statement in your KSH script file :
awk -f fmt.awk tmp.txt
2) If you don't want to use an external file, you can include all the awk program in your KSH...
You can try something like that:
#
# Proceed all records
#
{
records[NR] = $0; # Memorize record
keys[NR] = $1; # Memorize record key
++counts[$1]; # Count records with this key
sums[$1] += $2; # Summurize values for this key
}
#
# End of datas
#
END {
#
#...
\B
Matches everywhere but on a word boundary; that is it matches if
the character to the left and the character to the right are
either both "word" characters or both "non-word" characters.
\>
Constrains a RE to match the end of a string or to
precede a character that is not a digit...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.