Preserving file format and spacing in output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Preserving file format and spacing in output file
# 8  
Old 04-27-2012
Can you show an example of the desired output ? Can you post the awk script that was not working?
# 9  
Old 04-27-2012
Quote:
Originally Posted by panyam
Code:
 
With the above code, the string would be replaced but the alignment would not be preserverd. What I require is suppose column 1 is 45 chars and col 2 starts from 46th chars, even after substitution of the string the col 2 should start from 46th char only.

What if the new string which will replace column1 is more than "45" charactes in length?

Post a sample output on what exactly you are expecting.
Hi

No the new string will always have the string length less than 44 chars. It will not pass 45 chars limit

Sample text
_______________

Code:
"PROD GLOBAL"                        "BPROD Tray"  
"ABC LONDON"                         "Capla"                      
"ARAS GLOBAL COMPANY"          "AAC - Optiver"

Suppose I replace ARAS GLOBAL COMPANY with ARAS LIMITED, then also the column 2 shld start from 46th char only and not charecters before.

Thanks,
Sudeep

---------- Post updated at 08:18 PM ---------- Previous update was at 08:16 PM ----------

I am not able to preserve the alignment in the above post but it is like...
column A (length 45 chars)
column B (length 50 chars) starts from 46th char from left
# 10  
Old 04-27-2012
Please just show a sample output file.
# 11  
Old 04-27-2012
Quote:
Originally Posted by Scrutinizer
Please just show a sample output file.
Code:
 
sample.txt
__________
"PROD GLOBAL"                           "BPROD Tray" 
"ABC LONDON"                            "Capla" 
"ARAS GLOBAL COMPANY"                   "AAC - Optiver"
 
> sed 's/PROD GLOBAL/PROD/g' sample.txt> new_sample.txt 
 
new_sample.txt
__________
"PROD"                         "BPROD Tray" 
"ABC LONDON"                            "Capla" 
"ARAS GLOBAL COMPANY"                   "AAC - Optiver"
 
The required o/p file is 
 
new_sample.txt
__________
"PROD"                                  "BPROD Tray" 
"ABC LONDON"                            "Capla" 
"ARAS GLOBAL COMPANY"                   "AAC - Optiver"

Please note that the string to replace and the replacement string are user input, and replacement string has variable length but which is less than 45 chars in all the cases.

Last edited by sudeep.id; 04-27-2012 at 12:02 PM..
# 12  
Old 04-27-2012
There is a difference in format between the input file and the required output file if you look at the line with Capla. Is that line supposed to remain unchanged?
I gather the user input is
Code:
string1="PROD GLOBAL"

Code:
string2="PROD"

Is that assumption correct?
Does that need to be replace in every occurrence or only the first occurrence or only the last occurrence, for example?
# 13  
Old 04-27-2012
Quote:
Originally Posted by Scrutinizer
There is a difference in format between the input file and the required output file if you look at the line with Capla. Is that line supposed to remain unchanged?
I gather the user input is
Code:
string1="PROD GLOBAL"

Code:
string2="PROD"

Is that assumption correct?
Does that need to be replace in every occurrence or only the first occurrence or only the last occurrence, for example?
Sorry for typo... yes the assumption is correct. Only the first instance has to be replaced. I wrongly copied the command. It is

Code:
sed 's/PROD GOBAL/PROD/' sample.txt > new_sample.txt

I am not able to retain the proper formating while posting here. For clarity.. the first column starts at char 1 and the second column satrts from char 46. the spaces are getting trimmed while posting so i manually inserted the spaces to give a rough idea of the spacing.

Thanks,
Sudeep

Last edited by Scrutinizer; 04-27-2012 at 01:34 PM.. Reason: code tags
# 14  
Old 04-27-2012
Hi, no worries, but it important that you pay proper attention to the correctness of you post by using preview first. Go over it a couple of times. People are putting in time and effort to help and it is good if they waste as little time as possible...
You can retain proper formatting by using code tags.

The format of your sample is not 45/50 characters..
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 with printing output format from a file

Hi, I need help in printing data in below format from file extensions with .dml, i have listed details below file name is test_temp.dml, location in /home/users/test01/test_temp.dml file content: sample_type= record decimal(",") test_type; date("DD-MM-YYYY")(",") test_date... (2 Replies)
Discussion started by: AAHinka
2 Replies

2. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

3. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

4. Shell Programming and Scripting

format a file to this output

hi i need some help over here.. please help i have a log file as per below --------------------------------------------------------------------------------------------------------- JOB START DATE : 20110510204513 JOB ID : us2cap3ds9... (6 Replies)
Discussion started by: sitaldip
6 Replies

5. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

6. Shell Programming and Scripting

Change file output format

I have a file which has following contents usmtnz-dinfsi19 62 61 18400 18800 99.7 usmtnz-dinfsi19 62 61 18400 18800 99.7 i want the o/p to be like date (7 Replies)
Discussion started by: fugitive
7 Replies

7. Shell Programming and Scripting

format file output

Hi, I am trying to put a script together that allows for a command to be executed and then the output goes to a .html file. I am running the script on HPUX. I run: /var/fl/user/lmutil lmstat -a -c license_lic.dat > /web/results.html This saves the command to a .html file but the text is... (1 Reply)
Discussion started by: zerbitated
1 Replies

8. Shell Programming and Scripting

format the output from a file

hi , i need to format the output which is availble in a file file output is Following are the Process_Scheduler Domains running in the server Ram-pc VPORCL Following are the Application Server domains running in the server Ram-pc VPORCL01 VPORCL02 these value VPORCL,VPORCL01...... (5 Replies)
Discussion started by: becksram123
5 Replies

9. Shell Programming and Scripting

Output format - comparison with I/p file

Hi, I have a file which contains more than 1 lakh records like following: a. name, id, city, state, country, phone (Expected I/P file format) name, id, city,, state, country, phone (Current I/P file format ) I want to achieve following tasks, a, Remove the extra comma in the... (1 Reply)
Discussion started by: velappangs
1 Replies

10. Shell Programming and Scripting

Format the output of file

hello all Script and example of file #!/bin/sh #sh gdata.sh /users/testsuite/db/appl/ DATE=`date '+20%y-%m-%d'` echo $DATE for i in ${1}/$DATE/* ; do find $i -name daily -prune -o -name run.log -print -exec grep -c ! {} \; done > test.log. The test.log contains output like this ... (9 Replies)
Discussion started by: getdpg
9 Replies
Login or Register to Ask a Question