Reformatting of an output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reformatting of an output file
# 1  
Old 07-24-2017
Reformatting of an output file

Hi,

i've got the following output file:

Code:
170724_1600 | SYSTEM | 449 | 282 | 167 | 62
170724_1600 | CCS_SCP_DATA | 200 | 88 | 112 | 44
170724_1600 | CCS_SCP_SUBS_I | 2001 | 1751 | 250 | 87
170724_1600 | UIS_CDR_INDEX | 2001 | 1 | 2000 | 0
170724_1600 | LCP_INDEX | 200 | 5 | 195 | 2
170724_1600 | TOOLS | 200 | 144 | 56 | 72
170724_1600 | SMF_INDEX | 100 | 12 | 88 | 12

The idea is to format the result into this:

Code:
SYSTEM: Size=449, Used=282 (62%), Free=167, CCS_SCP_DATA:
 Size=200, Used=88 (44%), Free=112, .....

I've managed to turn the file with a comma seperated as follows:

Code:
cat outputfile | tr -d '|' | cut -d" " -f2- | tr '\n' ','

which results in:

Code:
SYSTEM  449  282  167  62, CCS_SCP_DATA  200  88  112  44, CCS_SCP_SUBS_I  2001  1751  250  87, UIS_CDR_INDEX  2001  1  2000  0, LCP_INDEX  200  5  195  2, TOOLS  200  144  56  72, ....

But can't seem to find a way to somehow enter those strings in result.

i was thinking that maybe there is some sort of bash array that i can use, but am not really familiar.
Do you have ideas how i can achieve this?

Rgds,
# 2  
Old 07-24-2017
Try:
Code:
awk -F' [|] ' '{printf "%s: Size=%s, Used=%s (%s%%), Free=%s\n", $2, $3, $4, $6, $5}' file

Which produces:
Code:
SYSTEM: Size=449, Used=282 (62%), Free=167
CCS_SCP_DATA: Size=200, Used=88 (44%), Free=112
CCS_SCP_SUBS_I: Size=2001, Used=1751 (87%), Free=250
UIS_CDR_INDEX: Size=2001, Used=1 (0%), Free=2000
LCP_INDEX: Size=200, Used=5 (2%), Free=195
TOOLS: Size=200, Used=144 (72%), Free=56
SMF_INDEX: Size=100, Used=12 (12%), Free=88

# 3  
Old 07-24-2017
Hello nms,

Could you please try following and let me know if this helps you.
Code:
awk -F' +[|] +' '{print $2":","Size="$3", ","Used=",$4 "(",$NF"%),", " Free="$5}'  Input_file

Thanks,
R. Singh
# 4  
Old 07-25-2017
Hi both,

Thanks for your input. Using:

Code:
awk -F'|' '{print $2":" "Size="$3 "Used="$4 "("$NF"%)" "Free="$5","}' cron_T-ORA001-OracleTablespaces | tr -d '[:space:]'

Nearly did the job:

Code:
SYSTEM:Size=449Used=282(62%)Free=167,CCS_SCP_DATA:Size=200Used=88(44%)Free=112,CCS_SCP_SUBS_I:Size=2001Used=1751(87%)Free=250,UIS_CDR_INDEX:Size=2001Used=1(0%)Free=2000,LCP_INDEX:Size=200Used=5(2%)Free=195,TOOLS:Size=200Used=144(72%)Free=56,SMF_INDEX:Size=100Used=12(12%)Free=88,ACS_DATA:Size=400Used=44(11%)Free=356,ACS_INDEX:Size=200Used=38(19%)Free=162,ACS_SUBURB_DATA1:Size=800Used=2(0%)Free=798,USERS:Size=100Used=1(1%)Free=99,CCS_SCP_INDEX:Size=200Used=108(54%)Free=92,UPC_INDEX:Size=200Used=3(1%)Free=197,ACS_SUBURB_INDEX1:Size=800Used=3(0%)Free=797,SMF_DATA:Size=100Used=18(18%)Free=82,CCS_SCP_SUBS:Size=2001Used=901(45%)Free=1100,UPC_DATA:Size=200Used=2(1%)Free=198,MMX_INDEX:Size=300Used=94(31%)Free=206,UIS_DATA:Size=400Used=15(3%)Free=385,MMX_DATA:Size=300Used=37(12%)Free=263,OSD_INDEX:Size=200Used=19(9%)Free=181,NP_DATA:Size=200Used=9(4%)Free=191,SYSAUX:Size=400Used=309(77%)Free=91,UIS_INDEX:Size=400Used=44(11%)Free=356,UIS_CDR:Size=2001Used=1(0%)Free=2000,LCP_DATA:Size=200Used=5(2%)Free=195,NP_INDEX:Size=200Used=13(6%)Free=187,UNDOTBS1:Size=3980Used=91(2%)Free=3889,OSD_DATA:Size=300Used=9(3%)Free=291,

What i'm searching for is if i can actually insert a space between any numeric character and the word "Used"

Code:
SYSTEM:Size=449 Used=282(62%) Free=167,....

# 5  
Old 07-25-2017
Hello nms,

Not sure completely, could you please try following and let me know if this helps you.
Code:
awk -F' +[|] +' '{val=val?val "," $2":Size="$3" Used=" $4 "(" $NF"%)  Free="$5:$2":Size="$3" Used=" $4 "(" $NF"%)  Free="$5} END{print val}'   Input_file

Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help reformatting input file

Hi, I have an input file that looks like this (columns are tab delimited: Data000005-RA GO:0003735 GO:0005840 GO:0006412 Data000005-RA GO:0003735 Data000009-RA GO:0003735 GO:0005622 GO:0005840 GO:0006412 ... (2 Replies)
Discussion started by: Fahmida
2 Replies

2. Shell Programming and Scripting

Reformatting a file for biological purpose

Dear ALL, I would really appreciate if you could help me in reformatting a file in this way: The file refers to a list of genetic coordinates, each lines has a score value and the associated chromosome is listed in the line starting with chrom . If more coordinates are found, the start... (2 Replies)
Discussion started by: paolo.kunder
2 Replies

3. Shell Programming and Scripting

Reformatting single column text file starting new line when finding particular string

Hi, I have a single colum file and I need to reformat the file so that it creates a new line every time it come to an IP address and the following lines are corresponding rows until it comes to the next IP address. I want to turn this 172.xx.xx.xx gwpusprdrp02_pv seinwnprd03... (7 Replies)
Discussion started by: kieranfoley
7 Replies

4. Shell Programming and Scripting

Stripping characters from a file and reformatting according to another one

Dear experts, my problem is pretty tricky. I want to change a file (see attached input.txt), according to another file (help.txt). The output that is desired is in output.txt. The example is attached. Note that -dashes should not be treated specially, they are considered normal characters,... (2 Replies)
Discussion started by: TheTransporter
2 Replies

5. Shell Programming and Scripting

Help for reformatting text file and creating new format

Hi all, I have an input file like 1,date,company,, 1,date,comapny,, 2,000,,,567,ACT,00,,,,KKG,M1,D45,,67J,+4500000000 2,000,,,567,ACT,00,,,,KKG,M6,D49,,56J,+6000 2,000,,,567,ACT,00,,7,,KKG,M3,D58,,68h,-70000 2,000,,,567,ACT,00,,,,KKG,M9,D95,,34m,0.00 3,total what i require is 1.I... (2 Replies)
Discussion started by: selvankj
2 Replies

6. Shell Programming and Scripting

reformatting xml file, sed or awk I think (possibly perl)

I have some xml files that cannot be read using a standard parser, or I am using the wrong parser. The issues seems to be spaces in some of the tags. Here is a sample,<UgUn 2 > <Un> -0.426753 </Un> </UgUn>The parser isn't able to find the number 2, so that information is lost, etc. It seems... (16 Replies)
Discussion started by: LMHmedchem
16 Replies

7. Shell Programming and Scripting

Help reformatting output

I have a command that gives me the output below: JAVA_HOME = C:/jdk1.5.0_11 Broker Performance Report for server 'app1' RMI_URL = rmis:// Parameter Kintana ItgDS DashboardDS ---------------------------- ------- ----- ----------- Connections count 41 ... (4 Replies)
Discussion started by: bwiebe
4 Replies

8. Shell Programming and Scripting

awk multiple file reformatting

I hopefully have a simple request - I need to process multiple files reformatting the output based on tags at the beginning of each line. So the data for the new 3 lines of the output file are in the HDR line and then the details are in the DTL tagged lines. for ifile in $indir do echo... (1 Reply)
Discussion started by: jason_v_brown
1 Replies

9. UNIX for Dummies Questions & Answers

Reformatting file

Hi, How can I reformat a file (text file) using unix command. This file was FTP'd from Mainframe and contains some garbage character at the end of each line. Each line contains special characters '<soh>' at the end which should have been spaces when I view it in emacs or nedit. I couldnt do find... (2 Replies)
Discussion started by: mrjunsy
2 Replies

10. Shell Programming and Scripting

Help capturing and reformatting buffered and unbuffered output

Ok, so I have a shell script which runs a specific command, and that command sends it's output to the display. At certain times, the command sends buffered output, and at other times, the command sends unbuffered output in the form of a % progress bar, so if I run the command, the output I receive... (0 Replies)
Discussion started by: vikingshelmut
0 Replies
Login or Register to Ask a Question