Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 5, 2024. It is now read-only.

Commit b104c70

Browse files
typos fixed, added note for inplace suffix
#27
1 parent 0167be7 commit b104c70

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

‎gnu_awk.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ I bought two bananas and three mangoes
927927
```
928928

929929
* to create backups of original file, set `INPLACE_SUFFIX` variable
930+
* **Note** that in newer versions, you have to use `inplace::suffix` instead of `INPLACE_SUFFIX`
930931

931932
```bash
932933
$ awk -i inplace -v INPLACE_SUFFIX='.bkp' '{gsub("three", "3")} 1' f1
@@ -1333,10 +1334,11 @@ $ awk '/END/{print p2} {p2=p1; p1=0ドル}' range.txt
13331334
1234
13341335
b
13351336
$ # save all lines in an array for generic case
1336-
$ awk '/END/{print a[NR-3]} {a[NR]=0ドル}' range.txt
1337-
BEGIN
1338-
a
1339-
$ # or use the reversing trick
1337+
$ # NR>n is checked to avoid printing empty line if there is a match
1338+
$ # within first n lines
1339+
$ awk -v n=3 '/BEGIN/ && NR>n{print a[NR-n]} {a[NR]=0ドル}' range.txt
1340+
6789
1341+
$ # or, use the reversing trick
13401342
$ tac range.txt | awk 'n && !--n; /END/{n=3}' | tac
13411343
BEGIN
13421344
a
@@ -1627,7 +1629,7 @@ Amy sports_rep
16271629
Tia placement_rep
16281630

16291631
$ awk -v OFS='\t' 'NR==FNR{r[1ドル]=2ドル; next}
1630-
{NF++; $NF = NR==1 ? "Role" : $NF=r[2ドル]} 1' list4 marks.txt
1632+
{$(NF+1) = FNR==1 ? "Role" : r[2ドル]} 1' list4 marks.txt
16311633
Dept Name Marks Role
16321634
ECE Raj 53 class_rep
16331635
ECE Joel 72
@@ -2170,7 +2172,7 @@ $ echo 'foo:123:bar:baz' | awk -f quotes.awk
21702172

21712173
```bash
21722174
$ awk -o -v OFS='\t' 'NR==FNR{r[1ドル]=2ドル; next}
2173-
{NF++; if(FNR==1)$NF="Role"; else $NF=r[2ドル]} 1' list4 marks.txt
2175+
{$(NF+1) = FNR==1 ? "Role" : r[2ドル]} 1' list4 marks.txt
21742176
Dept Name Marks Role
21752177
ECE Raj 53 class_rep
21762178
ECE Joel 72
@@ -2185,7 +2187,7 @@ File name can be passed along `-o` option, otherwise by default `awkprof.out` wi
21852187

21862188
```bash
21872189
$ cat awkprof.out
2188-
# gawk profile, created Tue Oct 24 15:10:02 2017
2190+
# gawk profile, created Mon Mar 16 10:11:11 2020
21892191

21902192
# Rule(s)
21912193

@@ -2195,12 +2197,7 @@ $ cat awkprof.out
21952197
}
21962198

21972199
{
2198-
NF++
2199-
if (FNR == 1) {
2200-
$NF = "Role"
2201-
} else {
2202-
$NF = r[2ドル]
2203-
}
2200+
$(NF + 1) = (FNR == 1 ? "Role" : r[2ドル])
22042201
}
22052202

22062203
1 {
@@ -2591,7 +2588,7 @@ nums.txt 10062.9
25912588
/dev/fd/63 10068.9
25922589
25932590
$ # step 4 - correctly initialize variables
2594-
$ awk 'BEGINFILE{sum=0} {sum += 1ドル} ENDFILE{print FILENAME, sum}' nums.txt <(seq 3)
2591+
$ awk '{sum+= 1ドル} ENDFILE{print FILENAME, sum; sum=0}' nums.txt <(seq 3)
25952592
nums.txt 10062.9
25962593
/dev/fd/63 6
25972594
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /