Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
There is a multi-word option
#!/bin/bash
NEED_STR='penultimate line'
FILE='need_file_path'
LAST=$(tail -1 $FILE)
sed -i '$ d' $FILE
echo "$NEED_STR" >> $FILE
echo "$LAST" >> $FILE
AWK script, takes the string to be inserted as an argument, redirect I / O to the necessary files:
BEGIN {
s = "\n"
}
{
if ( s != "\n" ) print s ;
s = $0 ;
}
END {
print ARGV [ 1 ] ;
print s ;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question