Therefore, I've added some lines(in green) of code to modify the output before print it in order to separate individual lines by "\n" and the fields by "|" as follow:
Code:
awk 'BEGIN{print "Category|Titles|Authors"}
/^(Category|Titles|Authors)/,/^$/ {
if ($0&&$0!~"^---") R=(R?R",":"")$1}
{R==gsub(/^Category,/,"",R);gsub(/,Category,/,"\n",R);
gsub(/,Titles,/,"|",R);gsub(/,Authors,/,"|",R)}
END {print R}' inputfile
With an inputfile with more data("books") within it, the output is:
Code:
Category|Titles|Authors
Adventure|Robinson-Crusoe,Saturday|Daniel-Defoe,Ian-McEwan
Fantasy
Literature|Ulysses
With this the output I'm looking for is 95% done, the last help I need is: How to modify the variable "R", as I've done so far, with gsub() adding "|" in all lines that have 1 or 2 fields with empty value?and get this final output:
I want to add 1 or 2 more gsub(/regexp/,"|",R) to reach this task, but I can't get the right Regexp for lines without "|" (to add 2 "|") and lines with only 1 "|" (to add 1 "|").Category field will always have a value.
* For reference I've uploaded the inputfile with more "books".
Any advice to get this would be very appreciated.
hi all
need your help.
I am wrting a script that will load data into the table.
then on another load will append the data into the existing table.
Regards
Ankit (1 Reply)
Hi All,
OS-Type=Sun-OS 5.8 Sparc9 Processor
Can I grep the previous 4 lines and next 4 lines of a matched pattern(context grep)?
For example here we need to monitor logs of live traffic.The data obtained from "tail -f LiveTrafficData.log"
looks something like this:-... (3 Replies)
I have files that store multiple data points for the same device "vertically" and include multiple devices. It repeats a consistant pattern of lines where for each line:
Column 1 is a common number for the entire file and all devices in that file
Column 2 is a unique device number
Column 3 is... (7 Replies)
Hello,
Is there any way in awk to put every line of a file in an array and so we can like this print the line we want.
For example, if we have this file
aaa eee
bbb fff
ccc ggg
ddd hhh
So we can print to the output the 3rd line only
ccc ggg
If it is possible, please put the... (7 Replies)
I am trying to add a line to a BASH shell script to print out a large variable length table on a web page. I am very new to this obviously, but I tried this with awk and it prints out every line twice. What I am doing wrong?
echo "1^2^3%4^5^6%7^8^9%" | awk 'BEGIN { RS="%"; FS="^"; } {for (i =... (6 Replies)
Hi Friends,
I have a file1
i want to retrieve only the fields which have DEP,CITY,TRANS as headers in other file.
Output:
I want to give the input as DEP,CITY,TRANS column names to get the output.
i used cut command .. but if i have 300 fileds it is more difficult to... (4 Replies)
Hi all, I'm trying to match the following two files with the code below:
awk -F, 'NR==FNR {a=$0; next} ($12,$4) in a {print $12,$1,a}' OFS="," file4.csv file3.csv
but the code does not print the entire row from file4 in addition to column 12 and 1 of file3.
file4:
o,c,q,co,ov,b... (1 Reply)
Dear all,
I am using the awk 'split' command to get the particular value.
FILE=InputFile_009_0.txt
Temp=$(echo $FILE | awk '{split($FILE, a, "e_"); print a}')
I would like to have the Temp take the value as : _009_0
... (4 Replies)
I have an file which have data in lines as follows
ad, findline=24,an=54,ab=34,av=64,ab=7989,ab65=34,aj=323,ay=34,au=545,ad=5545
ab,abc,an10=23,an2=24,an31=32,findline=00,an33=23,an32=26,an40=45,ac23=5,ac=87,al=76,ad=26... (3 Replies)