Skip to main content
tidyup
Source Link
Fedor
  • 89
  • 4

another possible BASH way - create a helper function which processes the stdin with read command and then prints extra line(s):

$ function append_lines(){ local data; while read -r data; do echo -en "$data"; done; echo "$*"; } $ echo "[`date `]" date | append_lines " +suffice_;line1" " ++line2" " +++line_3" [Mon Aug 21 16:00:37 CEST 2023][ +suffice_;line1 ++line2 +++line_3] $ echo "750/12.5" | bc | append_lines "/24" | bc 2 

where

  • while read -r data; do echo -en "$data"; done; - just passes the stdin (pipe) through. remove the -en modifier to print separate input lines.
  • echo "$*"; - prints all arguments of append_lines() to stdout

another possible BASH way - create a helper function which processes the stdin with read command and then prints extra line(s):

$ function append_lines(){ local data; while read -r data; do echo -en "$data"; done; echo "$*"; } $ echo "[`date `]"  | append_lines " +suffice_;line1" " ++line2" " +++line_3" [Mon Aug 21 16:00:37 CEST 2023][ +suffice_;line1 ++line2 +++line_3] $ echo "750/12.5" | bc | append_lines "/24" | bc 2 

where

  • while read -r data; do echo -en "$data"; done; - just passes the stdin (pipe) through. remove the -en modifier to print separate input lines.
  • echo "$*"; - prints all arguments of append_lines() to stdout

another possible BASH way - create a helper function which processes the stdin with read command and then prints extra line(s):

$ function append_lines(){ local data; while read -r data; do echo -en "$data"; done; echo "$*"; } $ date | append_lines " +suffice_;line1" " ++line2" " +++line_3" [Mon Aug 21 16:00:37 CEST 2023][ +suffice_;line1 ++line2 +++line_3] $ echo "750/12.5" | bc | append_lines "/24" | bc 2 

where

  • while read -r data; do echo -en "$data"; done; - just passes the stdin (pipe) through. remove the -en modifier to print separate input lines.
  • echo "$*"; - prints all arguments of append_lines() to stdout
added 65 characters in body
Source Link
Fedor
  • 89
  • 4

another possible BASH way - create a helper function which processes the stdin with read command and then prints extra line(s):

$ function append_lines(){ local data; while read -r data; do echo -en "$data"; done; echo "$*"; }   $ echo "[`date `]" | append_lines " +suffice_;line1" " ++line2" " +++line_3" [Mon Aug 21 16:00:37 CEST 2023][ +suffice_;line1 ++line2 +++line_3] $ echo "750/12.5" | bc | append_lines "/24" | bc 2 

where

  • while read -r data; do echo -en "$data"; done; - just passes the stdin (pipe) through. remove the -en modifier to print separate input lines.
  • echo "$*"; - prints all arguments of append_lines() to stdout

another possible BASH way - create a helper function which processes the stdin with read command and then prints extra line(s):

$ function append_lines(){ local data; while read -r data; do echo -en "$data"; done; echo "$*"; } $ echo "[`date `]" | append_lines " +suffice_;line1" " ++line2" " +++line_3" [Mon Aug 21 16:00:37 CEST 2023][ +suffice_;line1 ++line2 +++line_3] 

where

  • while read -r data; do echo -en "$data"; done; - just passes the stdin (pipe) through. remove the -en modifier to print separate input lines.
  • echo "$*"; - prints all arguments of append_lines() to stdout

another possible BASH way - create a helper function which processes the stdin with read command and then prints extra line(s):

$ function append_lines(){ local data; while read -r data; do echo -en "$data"; done; echo "$*"; }   $ echo "[`date `]" | append_lines " +suffice_;line1" " ++line2" " +++line_3" [Mon Aug 21 16:00:37 CEST 2023][ +suffice_;line1 ++line2 +++line_3] $ echo "750/12.5" | bc | append_lines "/24" | bc 2 

where

  • while read -r data; do echo -en "$data"; done; - just passes the stdin (pipe) through. remove the -en modifier to print separate input lines.
  • echo "$*"; - prints all arguments of append_lines() to stdout
added 58 characters in body
Source Link
Fedor
  • 89
  • 4

another possible BASH way - create a helper function which processes the stdin with read command and then prints extra line(s):

$ function append_lines(){ local data; while read -r data; do echo -en "$data"; done; echo "$*"; } $ echo "[`date `]" | append_lines " +suffice_;line1" " ++line2" " +++line_3" [Mon Aug 21 16:00:37 CEST 2023][ +suffice_;line1 ++line2 +++line_3] 

where

  • while read -r data; do echo -en "$data"; done; - just passes the stdin (pipe) through. remove the -en modifier to print separate input lines.
  • echo "$*"; - prints all arguments of append_lines() to stdout

another possible BASH way - create a helper function which processes the stdin with read command and then prints extra line(s):

$ function append_lines(){ local data; while read -r data; do echo -en "$data"; done; echo "$*"; } $ echo "[`date `]" | append_lines " +suffice_;line1" " ++line2" " +++line_3" [Mon Aug 21 16:00:37 CEST 2023][ +suffice_;line1 ++line2 +++line_3] 

where

  • while read -r data; do echo -en "$data"; done; - just passes the stdin (pipe) through
  • echo "$*"; - prints all arguments of append_lines() to stdout

another possible BASH way - create a helper function which processes the stdin with read command and then prints extra line(s):

$ function append_lines(){ local data; while read -r data; do echo -en "$data"; done; echo "$*"; } $ echo "[`date `]" | append_lines " +suffice_;line1" " ++line2" " +++line_3" [Mon Aug 21 16:00:37 CEST 2023][ +suffice_;line1 ++line2 +++line_3] 

where

  • while read -r data; do echo -en "$data"; done; - just passes the stdin (pipe) through. remove the -en modifier to print separate input lines.
  • echo "$*"; - prints all arguments of append_lines() to stdout
added 32 characters in body
Source Link
Fedor
  • 89
  • 4
Loading
Source Link
Fedor
  • 89
  • 4
Loading