Formatting text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting text file
# 15  
Old 07-22-2016
Hi Ravindra,

This is my input file.

Code:
pname tmgnsr.tpfile_01 analy, lists=8, lines=5900, duration cap: 27.682 seconds
pname tmgnsr.tpfile_01 analy, lists=5, lines=1234, duration cap: 5.12 seconds
pname tmgnsr.sdcfile_01 analy, lists=4, lines=878172, duration cap: 27.145 seconds
pname tmgnsr.sdcfile_02 analy, lists=4, lines=200, duration cap: 34.624 seconds
pname tmgnsr.sdcfile_03 analy, lists=4, lines=200, duration cap: 8.076 seconds
pname tmgnsr.mndfile_01 analy, lists=3, lines=900, duration cap: 37.393 seconds
pname tmgnsr.mndfile_03 analy, lists=1, lines=900, duration cap: 43.077 seconds
pname tmgnsr.mndfile_04 analy, lists=8, lines=5900, duration cap: 16.371 seconds
pname tmgnsr.mndfile_05 analy, lists=1, lines=30, duration cap: 10.967 seconds
pname tmgnsr.mndfile_06 analy, lists=8, lines=900, duration cap: 6.688 seconds
pname tmgnsr.mndfile_abc_01 analy, lists=8, lines=900, duration cap: 22.231 seconds

I want the output as below.

Code:
tmgnsr ,tpfile_01 , 8, 5900, 27.682
tmgnsr ,tpfile_01 , 5, 1234, 5.12
tmgnsr ,sdcfile_01 , 4, 878172, 27.145
tmgnsr ,sdcfile_02 , 4, 200, 34.624
tmgnsr ,sdcfile_03 , 4, 200, 8.076
tmgnsr ,mndfile_01 , 3, 900, 37.393
tmgnsr ,mndfile_02 , 1, 900, 43.077
tmgnsr ,mndfile_03 , 8, 5900, 16.371
tmgnsr ,mndfile_04 , 1, 30, 10.967
tmgnsr ,mndfile_05 , 8, 900, 6.688
tmgnsr ,mndfile_abc_01 , 8, 900, 22.231

Thanks.
# 16  
Old 07-22-2016
Hello ROCK_PLSQL,

Could you please try following and let me know if this helps.
Code:
awk -F"[,|=|: ]" '{sub(/\./," ,",$2);sub(/$/," ",$2);print $2 OFS $6 OFS $9 OFS $14}' OFS=", "   Input_file

Output will be as follows.
Code:
tmgnsr ,tpfile_01 , 8, 5900, 27.682
tmgnsr ,tpfile_01 , 5, 1234, 5.12
tmgnsr ,sdcfile_01 , 4, 878172, 27.145
tmgnsr ,sdcfile_02 , 4, 200, 34.624
tmgnsr ,sdcfile_03 , 4, 200, 8.076
tmgnsr ,mndfile_01 , 3, 900, 37.393
tmgnsr ,mndfile_03 , 1, 900, 43.077
tmgnsr ,mndfile_04 , 8, 5900, 16.371
tmgnsr ,mndfile_05 , 1, 30, 10.967
tmgnsr ,mndfile_06 , 8, 900, 6.688
tmgnsr ,mndfile_abc_01 , 8, 900, 22.231

Thanks,
R. Singh
# 17  
Old 07-22-2016
Hi,

Thanks for your answer.
It's working fine apart from space is coming after comma in first and second field.

Code:
tmgnsr ,tpfile_01 ,

it should be
Code:
tmgnsr,tpfile_01,

Thanks
Moderator's Comments:
Mod Comment I can't believe that "it should be" is intended to be in the actual output you want. I tried to fix your code tags to produce something that made sense, but I have no way to know if I correctly guessed at which spaces in that line are intended to be in the output you got.

Last edited by Don Cragun; 07-22-2016 at 05:29 PM.. Reason: Try to fix CODE tags.
This User Gave Thanks to ROCK_PLSQL For This Post:
# 18  
Old 07-22-2016
Quote:
Originally Posted by ROCK_PLSQL
Hi,

Thanks for your answer.
It's working fine apart from space is coming after comma in first and second field.

Code:
tmgnsr ,tpfile_01 ,

it should be
Code:
tmgnsr,tpfile_01,

Thanks
Moderator's Comments:
Mod Comment I can't believe that "it should be" is intended to be in the actual output you want. I tried to fix your code tags to produce something that made sense, but I have no way to know if I correctly guessed at which spaces in that line are intended to be in the output you got.
You seem to be saying that RavinderSingh13 gave you code in post #16 that produced exactly the output you said you wanted in post #15, and now you want different output without some of the spaces you said you wanted.

Instead of asking Ravinder to change his code to correct your incorrect specification, why don't you try to change the simple awk script Ravinder suggested to match your new requirements. Then, if you can't figure out which one, two, or three spaces need to be removed from his code to meet you NEW requirements, show us what you have done, explain what still isn't working correctly, and ask for help explaining where you are stuck.

Stop thinking of this forum as your unpaid programming staff and start thinking of it as a tutor to help you learn how to write your own code.

Moderator's Comments:
Mod Comment And, unless you edit post #1 in this thread to restore the original problem statement for this thread (as requested in post #10) before making any other posts, this thread will be closed and you may be banned from this site.
# 19  
Old 07-23-2016
If I remember right, you had spaces in your original posting, but anyway: Once you have the output fields, it is up to you how many spaces you insert.

Plus, as the moderator noted, it is nearly impossible to discuss a topic where the previous entries are modified. Things are so messed up, that I suggest that you start a completely new thread, post the code you are using so far, and ask whatever needs to be asked.
# 20  
Old 07-25-2016
Moderator's Comments:
Mod Comment The text removed from post #1 in this thread still has not been restored.
This thread is closed.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatting a text file

Hi All :), I have a formatting question and I am unsure on how I should proceed with my bash shell script. I am unsure weather to use perl or simply edit it in bash. I prefer bash but I am only aware of the awk utility to extract parts of a file, not edit output. Scenario: I have a file... (5 Replies)
Discussion started by: bstrizzy
5 Replies

2. Shell Programming and Scripting

[Solved] Formatting the text file

Hi All, I ahve requirement where I want to put the text file in into proper format. I am wondering how can i achieve that:- Host/Alias Name IP Address Resolved sinuiy01.infra.go2uti.com 10.240.8.158 N sinuid20.devtst.go2uti.com 10.240.8.230 N sinuid21.devtst.go2uti.com... (6 Replies)
Discussion started by: sharsour
6 Replies

3. Shell Programming and Scripting

Comparing and Formatting the text file

hi, I need a script which can format the below text file which contains comments file1.txt -------- //START //Name: some value //Date: //Changes:............. //..................... //END //START //Date: //Name: some value //Changes:............. //..................... (3 Replies)
Discussion started by: flamingo_l
3 Replies

4. Shell Programming and Scripting

Formatting the text file using shell script

How to add the filename to end of each line with | as seperator, except first and last line of the file(s) in directories(with diff tree structure) using shell script?. And also how to replace a list of strings with another set of strings, which is present in a file?. Kindly help out on... (1 Reply)
Discussion started by: av_vinay
1 Replies

5. Shell Programming and Scripting

Formatting text file in unix

Hi, I am using the following format command for formatting my text file in unix. awk -F":" '{ printf "%-50s%-1s%-50s\n", $1,":", $2}' filename > targetfile The target file is then sent as an attachment via email. When I view the target file in notepad multiple lines get spanned as a... (2 Replies)
Discussion started by: AAA
2 Replies

6. Shell Programming and Scripting

Formatting a text file to get data in exact line by line

I have my data something like this SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430693 07/01/2009 05:16:40 FR SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430746 07/01/2009 05:18:05 FR I want the output as follows.... (1 Reply)
Discussion started by: rdhanek
1 Replies

7. UNIX for Dummies Questions & Answers

formatting of the text file

Hi Guys, I have a file with contents in the below format DO_VJ_IDOC;03.23.2009;22:31:09; ZJDO_VJ_IDOC;03.23.2009;22:46:14; ZJDO_RESEND_FAILURES;03.24.2009;01:46:18; Now i need to replace the semicolons with tabs for which i am usig the sed command which gives the O/p as below ... (1 Reply)
Discussion started by: rohit.shetty84
1 Replies

8. UNIX for Dummies Questions & Answers

Text file formatting

Hi all! I'm new in unix, and faced with some difficulties. So I have text file f.e. "textfile" which contains rows like: aaa bbb ccc ddd How could I format it, so the file looks like: aaabbb cccddd Thanks in andvance (5 Replies)
Discussion started by: consta.v
5 Replies

9. Shell Programming and Scripting

Formatting a text file based on newline and delimiter characters

Hi Everybody, I need some help on formatting the files coming into unix box on the fly. I get a file some thing like this in a single line. ISA^M00^M ^M00^M ^M14^M006929681900 ^M01^M095449419 ... (5 Replies)
Discussion started by: ntekupal
5 Replies

10. Shell Programming and Scripting

text file formatting by perl

have a simple text file as input.i have to print that file in paragraph format.whenevr it finds "\n" in the input text it should start printing in next paragraph in output file.also a fixed amount of space should be given before start writing in every paragraph. the input and output file format... (5 Replies)
Discussion started by: avik1983
5 Replies
Login or Register to Ask a Question