44776

add some text to a bunch of lines

Question:

The first command does work as expected but not the second one. I want to add some text either at the beginning or the end.

# grep `date +'%y%m%d'` /var/log/mysqld.log 100101 10:56:00 mysqld started 100101 10:56:02 InnoDB: Started; log sequence number 1 2052750649 # sed 's/^/computer /g' < grep `date +'%y%m%d'` /var/log/mysqld.log bash: grep: No such file or directory # expected output computer 100101 10:56:00 mysqld started computer 100101 10:56:02 InnoDB: Started; log sequence number 1 2052750649

Answer1:

As you wrote it with input redirection, it looks for a file called grep in the current directory and tries to <em>read</em> its contents, not <em>execute</em> it. You need to use a pipe instead:

grep `date +'%y%m%d'` /var/log/mysqld.log | sed 's/^/computer /'

I also removed the 'g' modifier from your sed as it is completely unnecessary.

Answer2:

Just one awk command

awk -vd=$(date +'%y%m%d') '$0~d{ print "computer "$0 }' /var/log/mysqld.log

Recommend

  • Grails: cant create tables on mysql
  • finding values case insensitively with emojis
  • SQL: what kind of relation (1:1, 1:m, m:m,…) there is between this two tables?
  • Using sed to find and append multiple files with multiple lines?
  • How to extract distinct part of a string from a file in linux
  • SQL not inserting into table with relation in Yii
  • JAVA: Extract Server Certificates
  • Extract IP address from HTML document
  • Append string to output in shell
  • jQuery UI Tabs - bind tabs to links on the same page
  • shell script for grabbing data and subtracting
  • Can't detect mouse wheel event in safari
  • sed Removing whitespace around certain character
  • Read certain key from certain section of ini file (sed/awk ?)
  • Using grep to read a log for pattern1 in the file and print only lines containing pattern1. Stop sea
  • CSS Border DIV as a Shape
  • Get last insert id of Postgresql
  • Is it possible to generate a unique numeric value for each row in an iSeries table without looping?
  • Add two consecutive lines in sed
  • Remove characters after a specific character in column
  • C++ - Is destructor called when a vector holds objects?
  • Insert space after period using sed
  • Creating My Symmetric Key in C#
  • Use sed with regex and (
  • HttpListener.IsSupported is false on XP SP3
  • How can I replace the server in Web Component Tester
  • In-place sed command not working
  • Clear activity stack before launching another activity
  • Get specific string
  • Jenkins: FATAL: Could not initialize class hudson.util.ProcessTree$UnixReflection
  • Record samples being played with OpenAL
  • Where to put my custom functions in Wordpress?
  • Buffer size for converting unsigned long to string
  • Flexbox equal height doesn't work
  • How do you join a server to an Active Directory (domain)?
  • Why joiner is not used after Sequence generator or Update statergy
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal