Am new to AWk, Can anyone help me to get excepected output from given input please.
input file
student: name
details of them = details_needed
class: 5th_needed
adress: address_needed
Expected output:
details of them = 5th_needed = address_needed
---------- Post updated at 10:48 AM ---------- Previous update was at 10:27 AM ----------
CAn anyone help me please
yazu
2
% cat testfile
student: name
details of them = details_needed
class: 5th_needed
adress: address_needed
% awk 'BEGIN {RS=""; FS="\n"};
{ print gensub("student:[^\n]*\n([^=]*) = [^:]*: ([^\n]*)[^:]*: ", "\\1 = \\2 = ", "g") }' testfile
details of them = 5th_needed = address_needed
May be there is a better solution.
Its not working for me....Am using linux...Am getting whole file content.. Can you please help me?
yazu
4
Please give an example of the real text file with actual data and with several records.
Hi,
Try this
awk 'BEGIN {print "output"}
{sub(/\(/,"(")}
/^details/{a=$1 "="}
/^class/{a=a $2}
/^adress/{print a=a "=" $2}' input_file
---------- Post updated at 10:53 PM ---------- Previous update was at 10:51 PM ----------
Delimiter is missing..sorry..
Try this,
awk -F: 'BEGIN {print "output"}
{sub(/\(/,"(")}
/^details/{a=$1 "="}
/^class/{a=a $2}
/^adress/{print a=a "=" $2}' input_file
I update vasanth's solution
# awk -F':' '/^details/{split($0, a, "=")}; /^class/{b=$2} /^adress/{print a[1]"="b" ="$2}' file1
details of them = 5th_needed = address_needed
1 Like