Here are three different awk scripts to do this making different assumptions about the number of columns/row, and width of columns. If you input data is always less that 8 output columns per input line and you always have three input lines per output row, the 1st script is very simple.
If your input data has input lines that vary in length, but there are always three input lines per output row, the 2nd awk script below adjusts the output to match input field widths.
If you have a variable number of input lines per output row but the column 1 input line data always ends with a colon, the 3rd awk script below will adjust the number of rows and column widths based on the input file contents.
Here are the three awk scripts:
Code:
echo 'Following assumes 3 lines/row, tab separator:'
awk '{printf("%s%s", $0, NR % 3 ? "\t" : "\n")}' input
echo
echo 'Following assumes 3 lines/row, field width based on input:'
awk '
{ o[int((NR + 2)/3),++c] = $0
if(length($0) > w[c]) w[c] = length($0)
if(c == 3) c = 0
}
END { fmt = sprintf("%%-%ds%%-%ds%%s\n", w[1] + 2, w[2] + 2)
#printf("fmt=%s\n", fmt)
for(i = 1; i <= NR / 3; i++)
printf(fmt, o[i,1], o[i,2], o[i,3])
}' input
echo
echo 'Following assumes Column 1 data ends with ":", field width based on input:'
awk '
/:$/ { r++
if(c > mc) mc = c
c = 0
}
{ o[r,++c] = $0
if(length($0) > w[c]) w[c] = length($0)
}
END { for(i = 1; i <= r; i++) {
for(j = 1; j < mc; j++)
printf("%-*s", w[j] + 2, o[i, j])
printf("%s\n", o[i, mc])
}
}' input
When these three scripts are given the a file named input containing:
I have a file named "suspected" with series of line like these :
{'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''}
{'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Dear all-
I have a requirement to send an email via email with body content which looks something below-
Email body contents
--------------------
RequestType: Update
DateAcctOpened: 1/5/2010
Note that header information and data content should be normal text..
Please advice on... (5 Replies)
Hello,
Could you please let me know the correct format of CREATE TABLE statement with DATE format.
CREATE TABLE EMP_TABLE1 (
NAME VARCHAR(6) PRIMARY KEY,
ADDRESS VARCHAR(6),
BIRTH_DATE DATE
);
I want BIRTH_DATE to be in "YYYYMMDDHHMISS" format.
How we can create table with... (4 Replies)
hi guys,
i have a data with a column of p value (normal format and scientific combined). i want to creat a subset of data which only contains p-value:
data 1: p<10^7
data 2: p<0.01
how should i do it? many thanks!
data looks like:
rs7841347 128887490 1.695e-007
rs1241347 ... (4 Replies)
Hi,
I have EBCDIC format file and i wold like to convert normal string(user readable) in unix .
The source having the binary IBM file format
Sample Source Format:
... (3 Replies)
My Code
Hi Friends,
I need to get output in table format using unix shell script.For example my server CPU and memory utilization report will come as a mail with ordinary format but i want to make as table format.
Here two output finally we are getting:-
CPU utilization is... (2 Replies)
Hi All,
I have a output like below values
val1=test.com
val2=10.26.208.11
val3=en1
val4=test-priv1.com
val5=192.168.3.4
val6=en2
val7=test-priv2.com
val8=192.168.4.4
val9=en3
val10=test-vip.com
val11=10.26.208.9
val12=$val3
I want to convet this output values into below... (1 Reply)
I have one script which generate file called report.txt having following output
parameter_name status comment
banking ok NA
finance 30% hike NA
Loan_department ok 20%
HR_Group defaulters Ajay
I wanted to convert this file into tabular form.
You can see each line contain 3 words and... (7 Replies)
Hi,
OS: Redhat 7.5
shell: Bash
Wrote below script to login into oracle via shell script and trying to reset locked account..It works as expected. But I need specific output << EOF should go to target terminal not all out put
running below script from ansible command line..
#!/bin/bash... (1 Reply)