bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#65416: Feature request: include first line of file in output


From: Paul Jackson
Subject: bug#65416: Feature request: include first line of file in output
Date: Wed, 23 Aug 2023 03:20:26 -0500
User-agent: Cyrus-JMAP/3.9.0-alpha0-647-g545049cfe6-fm-20230814.001-g545049cf

sed and awk can also to this (1st line plus any matching lines)

Following transcript from zsh session on my fast Ryzen:

$ <<-'@@' time sh -c "grep -m1 USER && grep carenas"
USER,TIP
john,0
jane,10
carenas,100
@@
USER,TIP
carenas,100
sh -c "grep -m1 USER && grep carenas"  0.00s user 0.00s system 93% cpu 0.003 
total

$ <<-'@@' time sed -n -e 1p -e /carenas/p
USER,TIP
john,0
jane,10
carenas,100
@@
USER,TIP
carenas,100
sed -n -e 1p -e /carenas/p  0.00s user 0.00s system 80% cpu 0.001 total

$ <<-'@@' time awk 'NR == 1 || /carenas/'
USER,TIP
john,0
jane,10
carenas,100
@@
USER,TIP
carenas,100
awk 'NR == 1 || /carenas/'  0.00s user 0.00s system 88% cpu 0.002 total

As I expected, sed is fastest, grep next, and awk slowest of the three,
but the 1, 2, and 3 millisecond totals are within the margin of test error.

-- 
                Paul Jackson
                pj@usa.net





reply via email to

[Prev in Thread] Current Thread [Next in Thread]