Skip to main content
Post Undeleted by gniourf_gniourf
added 423 characters in body
Source Link
gniourf_gniourf
  • 47.4k
  • 10
  • 104
  • 113

========================= misread question ===========================To edit a file, you can use ed, the standard editor:

line=' bcm2708.w1_gpio_pin=20'
file=/boot/cmdline.txt
if ! grep -q -x -F -e "$line" <"$file"; then
    ed -s "$file" < <(printf '%s\n' 1 a "$line" . 1,2j w q)
fi

ed's commands:

  • 1: go to line 1
  • a: append (this will insert after the current line)
  • We're in insert mode and we're inserting the expansion of $line
  • .: stop insert mode
  • 1,2j join lines 1 and 2
  • w: write
  • q: quit

========================= misread question ===========================

To edit a file, you can use ed, the standard editor:

line=' bcm2708.w1_gpio_pin=20'
file=/boot/cmdline.txt
if ! grep -q -x -F -e "$line" <"$file"; then
    ed -s "$file" < <(printf '%s\n' 1 a "$line" . 1,2j w q)
fi

ed's commands:

  • 1: go to line 1
  • a: append (this will insert after the current line)
  • We're in insert mode and we're inserting the expansion of $line
  • .: stop insert mode
  • 1,2j join lines 1 and 2
  • w: write
  • q: quit
Post Deleted by gniourf_gniourf
Source Link
gniourf_gniourf
  • 47.4k
  • 10
  • 104
  • 113

========================= misread question ===========================