Reputation: 5119
How would I get like line 78 from history in Bash?
Like I know that I could do something along the lines of:
history | grep 78 | \
awk '{idex=2; while (idex <= NF) { printf $idex " "; idex++} print }' | \
sed '2!d; s/\s\s[0-9]*.*$//'
The text that I'm trying to get out of this is:
npm uninstall foo; npm install -g foo
Upvotes: 1
Views: 444
Reputation: 10039
history | sed -n "`78 {s/^ *[0-9]\{1,\}[[:space:]]*\([^ ]\)/\1/p;q;}"
if you absolutely want sed and use of history command (for example to add a "#" at the start of the line to secure any action of string) or in ksh where !78:p
does not work
Upvotes: 1
Reputation: 531125
The p
modifier will print any history expansion instead of executing it.
!78:p
Upvotes: 4