Help in preserving special characters from input file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in preserving special characters from input file
# 1  
Old 01-28-2010
Help in preserving special characters from input file

Hi Forum.

I've tried to search online for a solution but I cannot seem to find one.

Hopefully, someone here can help me out. I would appreciate it.

Input file abc.txt:

[S_M_F_ING_MTG_COM_CUSTOMER_EXTRACT]
$InputFile_Borrower=CMTSLST\EDW_COMMERCIAL_MTGE_BORROWER_dat.lst
$InputFile_Customer=CMTSLST\EDW_COMMERCIAL_MTGE_CUSTOMER_dat.lst
$OuputFile_BorrowerNoGridID=CMTS\cm_borrower_exception_no_grid_id.out
$OutputFile_BorrowerDup=CMTS\cm_borrower_exception_dup.out

Output from script:
[S_M_F_ING_MTG_COM_CUSTOMER_EXTRACT]
$InputFile_Borrower=CMTSLST\EDW_COMMERCIAL_MTGE_BORROWER_dat.lst
$InputFile_Customer=CMTSLST\EDW_COMMERCIAL_MTGE_CUSTOMER_dat.lst
$OuputFile_BorrowerNoGridID=CMTS$OutputFile_BorrowerDup=CMTS

And here's the simple sample script to read/output the input file:

cat abc.txt | while read -r line
do
echo $line
done

The read "-r" option is suppose to treat the input data as raw, but I think the script is trying to interpret the line $OuputFile_BorrowerNoGridID=CMTS\cm_borrower_exception_no_grid_id.out
.... as \c special character.

I've read that single quotes can preserve the input data as is with no interpretation but I'm not sure how to implement it in my above script.

Thanks.
# 2  
Old 01-28-2010
Do you have only 5 lines in your file and do you want to discard the last line?
Please elaborate your question.
# 3  
Old 01-28-2010
yes well, the trouble is the echo.

what exactly are you trying to achieve?
# 4  
Old 01-28-2010
Sorry if I wasn't clear.

I'm trying to preserve the data from the input file As is.

Basically, if I was going to output the script to another file def.txt, then
file abc.txt should be identical to def.txt

I don't want my script to interpret any special characters from the input file.

Thank you.
# 5  
Old 01-29-2010
So the files abc.txt and def.txt should be identical?

Why don't you use the cp command?

Homework?
# 6  
Old 01-29-2010
Quote:
Originally Posted by pchang
I've read that single quotes can preserve the input data as is with no interpretation but I'm not sure how to implement it in my above script.
What shell ? , works for me in bash(see below)
Code:
# cat file
[S_M_F_ING_MTG_COM_CUSTOMER_EXTRACT]
$InputFile_Borrower=CMTSLST\EDW_COMMERCIAL_MTGE_BORROWER_dat.lst
$InputFile_Customer=CMTSLST\EDW_COMMERCIAL_MTGE_CUSTOMER_dat.lst
$OuputFile_BorrowerNoGridID=CMTS\cm_borrower_exception_no_grid_id.out
$OutputFile_BorrowerDup=CMTS\cm_borrower_exception_dup.out

# while read -r line;do echo $line;done < file
[S_M_F_ING_MTG_COM_CUSTOMER_EXTRACT]
$InputFile_Borrower=CMTSLST\EDW_COMMERCIAL_MTGE_BORROWER_dat.lst
$InputFile_Customer=CMTSLST\EDW_COMMERCIAL_MTGE_CUSTOMER_dat.lst
$OuputFile_BorrowerNoGridID=CMTS\cm_borrower_exception_no_grid_id.out
$OutputFile_BorrowerDup=CMTS\cm_borrower_exception_dup.out

# 7  
Old 01-29-2010
Probably his shell/OS is using an echo statement that interprets escape sequences by default.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Rename File Name with Special Characters

I am trying to rename files with spaces and other characters and not able to be successful. FileNames: UPLOAD REFERENCE.xls UPLOAD MASS REFERENCE.XLS find /UPLOAD REFERENCE/ -depth -type f -name "* *" -exec rename " " "_" "{}" ";" The above one is successful to replace spaces... (1 Reply)
Discussion started by: eskay
1 Replies

2. Shell Programming and Scripting

How to delimit the fields of a input file which has special characters?

Hi All, I am a newbie to Shell scripting. I have a requirement to Delimit the file fields of a Input file having special characters and spaces with ";". Input File ---------------------------------- Server Port ---------------------------------- Local ... (5 Replies)
Discussion started by: Suganbabu
5 Replies

3. Red Hat

Special control characters in file

Hi Guys, We receive some huge files on to Linux server. Source system use FTP mechanism to transfer these files on our server. Occasionally one record is getting corrupted while transfer, some control characters are injecting into the file. How to fix this issue ? please advice ? Sample... (2 Replies)
Discussion started by: srikanth38
2 Replies

4. Shell Programming and Scripting

File containing special characters

Hello All, I am facing challenges in order to transfer a file from windows to unix box,the file contains a special character '×' ,now when I am transferring the file from windows to unix that special character converted to something else like 'Ã' ,another thing I have noticed that the hardware is... (1 Reply)
Discussion started by: prarat
1 Replies

5. Shell Programming and Scripting

Check input for lenght, special characters and letter case

I made menu script for users so they can run other script without going in shell just from menu. But i must control their input. These are criteria: Input must have 4 signs First two signs are always lower case letters Input shall not have some special signs just letters and numbers ... (1 Reply)
Discussion started by: waso
1 Replies

6. Shell Programming and Scripting

Ommiting special characters as input - Help

Hey Everyone, I'm quite new to unix (hence the 0 posts!) and im trying to write a simple program that outputs what the user types in to the screen, as long as it is a letter. This part works fine, however, when a "\" is entered doesnt not display anything and moves to the next line. Is... (11 Replies)
Discussion started by: ultiron
11 Replies

7. Shell Programming and Scripting

Bourne Shell: Special characters Input Prevention

Environment: Sun UNIX Language: Bourne Shell Problem: I am writing a script that allows user to key in a directory. Example: /root/tmp. Since the user can key in anything he/she wants, I need to validate to make sure that he/she does not key in anything funny i.e.... (37 Replies)
Discussion started by: totziens
37 Replies

8. UNIX for Dummies Questions & Answers

How to delete a file with special characters

I don't now exactly how I did it, but I created a file named " -C " cexdi:/home1 $ls -lt total 1801336 -rw------- 1 cexdi ced-group 922275840 23 mars 10:03 -C How do I delete this file ? cexdi:/home1 $rm -C rm: invalid option -- C Syntax : rm filename ... Doesn't work...... (5 Replies)
Discussion started by: yveslagace
5 Replies

9. UNIX for Dummies Questions & Answers

Replace Special characters in a file

Hi, I have a data like this in a file, 402003279034002000100147626030003300010000000000002000029000000 ær^M^\MÍW^H I need to replace those special char to some other char like # or $ Is there any ways to do it... I tried commands tr,sed and many but it was not able to replace because... (1 Reply)
Discussion started by: solai
1 Replies

10. UNIX for Dummies Questions & Answers

how to see special characters in a file using vi

Hi, I have a file which has special characters. I can't see them when I "vi" the file. But I am sure there are some special un seen characters. How can I see them? Please help. Thx (6 Replies)
Discussion started by: jingi1234
6 Replies
Login or Register to Ask a Question