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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use of tr command to translate after 1st character of each line in a file
# 1  
Old 09-27-2014
Use of tr command to translate after 1st character of each line in a file

Hello,


I have an input file contaning following data:

Code:
< 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 > in a file with ; symbol


output should be like this:

Code:
<;12345;5454;77;qwert< yuyuy;ruwuriwru> yyyw;
>;35353;68686;424242;hrjwhrwrwy< dgdgd;

Thanks in advance

Last edited by Scrutinizer; 09-27-2014 at 09:57 PM.. Reason: CODE tags
# 2  
Old 09-27-2014
Quote:
Originally Posted by abhi001cse
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 > in a file with ; symbol


output should be like this:

<;12345;5454;77;qwert< yuyuy;ruwuriwru> yyyw;
>;35353;68686;424242;hrjwhrwrwy< dgdgd;

Thanks in advance
Hello abhi001cse;
Welcome to forum, please use code tags while posting codes and commands.
Following awk solution may help you.

Code:
awk -F";" '{sub(/ /,";",$1);print}' OFS=";" Input_file

Output will be as follows.

Code:
<;12345;5454;77;qwert< yuyuy;ruwuriwru> yyyw;
>;35353;68686;424242;hrjwhrwrwy< dgdgd;

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 09-27-2014
Thanks a lot Ravinder.Its working fine
# 4  
Old 09-27-2014
how about
Code:
sed -r 's/^(<|>) /\1;/' file

btw: you can't use tr for that; it will replace ALL occurrences, not just the first.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. UNIX for Dummies Questions & Answers

Cut command doesn't remove (^C) character from only first line

I have a file which has first 2 junk characters(X^C) at beginning of each line in file. When i run cut -c 2- filename it removes junk characters from all lines except on first line it keeps one junk character control C(^C). Not sure why it is not removing only from first line. (2 Replies)
Discussion started by: later_troy
2 Replies

3. Shell Programming and Scripting

Unix command to select first few characters and last character of a line

I have a huge file and I want to select first 10 charcters and last 2 characters of everyline and than will filter the unique line. I know, it must be easy bt I am new to unix scripting:) Ex. I have file as below and need to e3kbaird and last 2 characters. and than unique records. ... (3 Replies)
Discussion started by: Sanjeev Yadav
3 Replies

4. Shell Programming and Scripting

Ignore the 255 character limit of command line

Hi I would just like to ask if there is a way for UNIX to ignore/overcome the 255 character limit of the command line? My problem is that I have a really long line of text from a file (300+ bytes) which i have to "echo" and process by adding commands like "sed" to the end of the line, like... (5 Replies)
Discussion started by: agentgrecko
5 Replies

5. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

6. Shell Programming and Scripting

Awk not working due to missing new line character at last line of file

Hi, My awk program is failing. I figured out using command od -c filename that the last line of the file doesnt end with a new line character. Mine is an automated process because of this data is missing. How do i handle this? I want to append new line character at the end of last... (2 Replies)
Discussion started by: pinnacle
2 Replies

7. Shell Programming and Scripting

How to translate character and font sets ?

Hi, below is an example of dialog script from the net, I would like to run from a command line in putty terminal opened session. The issue is some characters get replaced by dots. Could you advise me a solution to edit the following string into window character set accepted by putty ? I... (2 Replies)
Discussion started by: jack2
2 Replies

8. Shell Programming and Scripting

How can use the perl or other command line to calculate the length of the character?

For example, if I have the file whose content are: >HWI-EAS382_30FC7AAXX:7:1:927:1368 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA >HWI-EAS382_30FC7AAXX:7:1:924:1373 ACGAACTTTAAAGCACCTCTTGGCTCGTATGCCGTC I want my output calculate the total length of nucleotide. So my output should look like this:... (1 Reply)
Discussion started by: patrick chia
1 Replies

9. UNIX for Dummies Questions & Answers

Need to serach if a new line character exists on the last line in a file

I have a file in which I need to search if a new line character exists on the last line in the file. Please let me know how can I achieve it using Unix commands? (10 Replies)
Discussion started by: sunilbm78
10 Replies
Login or Register to Ask a Question