Need a ksh script for adding the space at the end of record in a flat file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a ksh script for adding the space at the end of record in a flat file
# 1  
Old 05-08-2012
Need a ksh script for adding the space at the end of record in a flat file

Hi,

I need a ksh script for the below requirement:
i have a Delimited flat file with 200 records delimiter is '|~|'
i need a script to insert space at the end if the record is ending with delimiter '|~|'
if it didnt end with delimiter it should not append space.

Example: ram|~|2|~| ---space should be appended
shyam|~|2|~|4 ----space should not be appended

please help me with this i need the complete script.

Thank you!

Last edited by srikanth_sagi; 05-08-2012 at 08:17 AM..
# 2  
Old 05-08-2012
Try:
Code:
awk '/\|~\|$/{$0=$0" "}1' file

# 3  
Old 05-08-2012
Hi,

Can you please give me the script,because i didnt know how to read the flat file and rotate the loop for each and every record in the flat file
# 4  
Old 05-08-2012
This will do all those things. Try running:
Code:
awk '/\|~\|$/{$0=$0" "}1' file > new_file

and then compare file and new_file.
This User Gave Thanks to bartus11 For This Post:
# 5  
Old 05-08-2012
Quote:
Originally Posted by srikanth_sagi
Hi,

I need a ksh script for the below requirement:
i have a Delimited flat file with 200 records delimiter is '|~|'
i need a script to insert space at the end if the record is ending with delimiter '|~|'
if it didnt end with delimiter it should not append space.

Example: ram|~|2|~| ---space should be appended
shyam|~|2|~|4 ----space should not be appended

please help me with this i need the complete script.

Thank you!
Just to get the requirement right, are you looking to create a fixed width output file?

If you have the data you suggest:-
Code:
ram|~|2|~|
shylam|~|2|~|4

... then you could pass this through sed to add trailing space, but how much do you want? A single character perhaps or pad to a fixed length?


Hoping I can help,
Robin
Liverpool/Blackburn
UK

Last edited by rbatte1; 05-08-2012 at 08:41 AM.. Reason: Code tagging
# 6  
Old 05-08-2012
Hi,

I just want one single space if the records ends with a delimter.
if the record doesnt end with delimter nothing should be appended

Thanks!
# 7  
Old 05-08-2012
Ha, I'm beaten to it with the awk

A very good answer. Does it make sense?



Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with awk script to append seq num at end of record

Hi Unix forum. I have the following requirement to add a sequence value to each record in a file but only if it meets certain conditions. Field value in pos. 1 and 2 must be '0B' or 'OA' else leave as is. Sequence value must be preserved for each OB and OA pair. Data Before: 123 456... (5 Replies)
Discussion started by: pchang
5 Replies

2. UNIX for Dummies Questions & Answers

To flat file, append null or space if its length is less than 10

Hi, We receive flat files with fixed width data Now our goal is append from right null or space to each record if the lenght of the record is less than for example 10. for example 123 45 6 0 123 45 123 45 6 123 and output should be 123 45 6 0 123 45**** 123 45 6**... (7 Replies)
Discussion started by: shharrath
7 Replies

3. Shell Programming and Scripting

Adding end of line character in the last record

Need to add end of line character to last record in a fixed width file. When i take the record length of each line, for all the records it gives example like 200 except the last line as 199. Due to this my other script fails. Please help me on this. (4 Replies)
Discussion started by: Amrutha24
4 Replies

4. Shell Programming and Scripting

Script adding ^M to end of line

I trying to make a simple script to get info from remote servers my problem is the output of this line- SERVER_NAME=`ssh -t $USER@$REMOTESERVER 'hostname'`the output is linux1^M I would like to remove the ^M where is my error? Many Thanks -Steve (1 Reply)
Discussion started by: shoodlum
1 Replies

5. Shell Programming and Scripting

How to add trailer record at the end of the flat file in the unix ksh shell scripting?

Hi, How to add trailer record at the end of the flat file in the unix ksh shell scripting can you please let me know the procedure Regards Srikanth (3 Replies)
Discussion started by: srikanth_sagi
3 Replies

6. Shell Programming and Scripting

how to add blank spaces at the end of every record in a file.

hi, Does anyone has any idea in adding few blank spaces at the end of every record in a file. Eg: file.txt Baby Boy Kim 1234 Baby Boy Vik 1334 Desired output:- output.txt Baby Boy Kim 1234 Baby Boy Vik 1334 I want to add 10 blank spaces at the end every record in file.txt (3 Replies)
Discussion started by: techmoris
3 Replies

7. Shell Programming and Scripting

Adding a footer to a flat file

I wanted to know if there is a way to add a footer to a flat file that is being extracted by a sql query. so if the query extracts 1000 rows, in the flat file it appends the last line as 1000. Is there a way to do so? Thanks (1 Reply)
Discussion started by: rudoraj
1 Replies

8. Shell Programming and Scripting

append a record at the end of a file

Hi all, i have to append a record at the end of the file(a file which is already with some records).how do i do?please help me? is there any way of doing this with "SED" command.i am not sure.plz help me on this. would appreciate your ideas!!!! bye rao. (3 Replies)
Discussion started by: raoscb
3 Replies

9. Shell Programming and Scripting

splitting a record and adding a record to a file

Hi, I am new to UNIX scripting and woiuld appreicate your help... Input file contains only one (but long) record: aaaaabbbbbcccccddddd..... Desired file: NEW RECORD #new record (hardcoded) added as first record - its length is irrelevant# aaaaa bbbbb ccccc ddddd ... ... ... (1 Reply)
Discussion started by: rsolap
1 Replies

10. UNIX for Dummies Questions & Answers

adding a column at the end of the record

hello., i have a .txt file. inside the .txt file i have., /home/ss/cca.costco.transaction_date /home/sk/cca.costco.transaction_date /home/st/cca.costco.transaction_date /home/sv/cca.costco.transaction_date cca.costco.transaction_date is the file name. inside the file there are some... (2 Replies)
Discussion started by: pavan_test
2 Replies
Login or Register to Ask a Question