I want to read the first six characters of a text file in a line and add to it any other non-empty line in this file with this line. An example of such a file could be:
04/17 Walmart .toys $ 70 .cash $ -70
Caltex .gas 20 $ .cheque $ -20
McDonalds .burger 1 $ .cash $ -1
Each record, i.e.: each non-empty line, needs a date that, for reasons of simple data entry, was entered only in the first line. Entries are separated by 1 or more blank lines. The result will look like this:
04/17 Walmart .toys $ 70 .cash $ -70
04/17 Caltex .gas 20 $ .cheque $ -20
04/17 McDonalds .burger 1 $ .cash $ -1
I can match non-empty strings with things like ^ [^ @] + [] *. [] ([^; {}:] +) [] * $ , but I don’t know how to implement this for non-empty strings.
This Bash script looks attractive to me, but I don’t know how to insert my line at the beginning then.
I also cannot find a direct answer to my question about Stack Overflow.
script, :
read -n 6 date < $1
sed 's/^/$(echo $date)/' | \
sed 's/^$(echo $date)\n//' | > $newName
(, : '04/17 ') , , .
, , sed :
sed: -e expression