I have 32 cells in a file so i need to read the name of the file and append the file name at the starting of every line how can i do it
example
MACRO
This can be done with a relatively simple awk
script, as per the following transcript:
pax$ printf "MACRO XYZ\nline 2\nline3\n\nMACRO GEN\nline 6\n\n\n" | awk '
...$ $1=="MACRO"{mac=$2;print;next}$NF>0{print mac" "$0;next}{print}'
MACRO XYZ
XYZ line 2
XYZ line3
.
MACRO GEN
GEN line 6
.
.
(those .
characters are added by me just to show where the blank lines are).
Expanding on the script:
$1 == "MACRO" { # If first word is macro:
mac=$2; # store second word,
print; # print line,
next # and go get next line.
}
$NF > 0 { # Otherwise, if line has some fields:
print mac" "$0; # print stored macro name before line,
next # and go get next line.
}
{ # Otherwise (lines with no fields):
print # just print it as is.
}