Translate Text File w/ shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Translate Text File w/ shell
# 1  
Old 09-30-2011
Translate Text File w/ shell

Hello everyone!

I'm having some problems trying to translate a text file.

I've found some TR and SED commands but doesnt work exactly as I need.

The point is:

1. Replace all the letters with accent of a text file, like this: √>A Ń>A ’>o
2. Replace all the special characters with a blank space, like this: $>' ' #>' '
3. I can't generate an output file, i need to do this 'translation' in the same file, without another one!

I'm a lil bit lost with this situation!

Can you help me?

Than you so much, Ulysses from Brazil.
# 2  
Old 09-30-2011
How is the original file encoded? (ascii, utf-8, unicode, etc..)

What is your locale set to?

Which/whose sed/tr are you using (ie OS vendor)
This User Gave Thanks to Skrynesaver For This Post:
# 3  
Old 09-30-2011
How is the original file encoded? (ascii, utf-8, unicode, etc..)
UNIX-ANSI
What is your locale set to?
Code:
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Which/whose sed/tr are you using (ie OS vendor)

I tried these:
Code:
perl -e "s/search_str/replacement_str/g;" -pi test.dat

(but this command is per word, not perr letter/character)
Code:
tr -d '[:punct:]' < teste.dat > teste.dat

(but this generate another file...)

---------- Post updated at 01:13 PM ---------- Previous update was at 09:53 AM ----------

any suggestion? Smilie

Moderator's Comments:
Mod Comment My suggestions: 1. Please use code tags; 2. Please don't "bump" posts. This is a forum, not a drive-thru-<...>; 3. Try "googling" w/ anything. Use a descriptive subject for better results.

Last edited by Scott; 09-30-2011 at 04:20 PM.. Reason: Code tags
# 4  
Old 09-30-2011
Perl incorporates the tr command itself if you have to avoid temporary files, this is the equivalent of a series of single character substitution regexes.
search for "tr/SEARCHLIST/REPLACEMENTLIST/cds" in
Code:
perldoc perlop

Why can't you create a temp file and move it back anyway?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

2. Solaris

Translate file name to disk blocks on UFS

Is there any way to translate a file name to the underlying file system's disk blocks/sectors/extents on UFS (Solaris OS on Sparc)? I found several ways to do it on linux file systems like ext2/3/4, using command like hdparm -- fibmap and filefrag. I also found one equivalent way to get that... (9 Replies)
Discussion started by: dorbaruch
9 Replies

3. Shell Programming and Scripting

Need help to write a shell script to convert text file to excel file.

Hi Everyone, I want your help to write a script which will take text file as input and on the basis of delimiter ":"script will create excel sheet. Example input: IpAdress:InstanceName:Port:ServerName 10.255.255.1:abc:2232:xyz_abc Output should be an excel sheet like below: Column... (8 Replies)
Discussion started by: akabhinav18
8 Replies

4. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

5. Shell Programming and Scripting

Use of tr command to translate after 1st character of each line in a file

Hello, I have an input file contaning following data: < 12345;5454;77;qwert< yuyuy;ruwuriwru> yyyw; > 35353;68686;424242;hrjwhrwrwy< dgdgd; I have first character as '<' or '>'and after that one space is their in each line I just want to replace 1st space encountered after < or >... (3 Replies)
Discussion started by: abhi001cse
3 Replies

6. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

7. Shell Programming and Scripting

shell or perl script needed for ldif file to text file conversion

This is the ldf file dn: sdcsmsisdn=1000000049,sdcsDatabase=subscriberCache,dc=example,dc=com objectClass: sdcsSubscriber objectClass: top postalCode: 29600 sdcsServiceLevel: 10 sdcsCustomerType: 14 givenName: Adelia sdcsBlackListAll: FALSE sdcsOwnerType: T-Mobile sn: Actionteam... (1 Reply)
Discussion started by: LinuxFriend
1 Replies

8. Shell Programming and Scripting

Plz Help To convert xml file to text file using bourn shell scripts

If someone out there could help me out with this problem. I would really appreciate it. I am trying to convert xml into text file(fixed length) using Unix Borne shell scripts. My xml file: <root> <header_rec recordtype="00"> <record_id>00</record_id> <country_code>AK></country_code>... (0 Replies)
Discussion started by: ram2s2001
0 Replies

9. Shell Programming and Scripting

translate text (1 position) with sed

Hello, I'm trying to translate a fixed length (the first 6 positions) that begins with a 0 to overwrite the field with an *. Any suggestion? File 1 ------- 013344 01:20 222343 19:30 233333 20:30 File 2 (result) ----------------- ****** 01:20 222343 19:30 233333 20:30 (5 Replies)
Discussion started by: peterk
5 Replies
Login or Register to Ask a Question