Remove blank space and insert special character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove blank space and insert special character
# 1  
Old 06-27-2014
Remove blank space and insert special character

Hi Folks,

I have a huge data of the below format
Code:
abc       #apple      1200 06/23
ghj        #orange    1500 06/27
uyt       #banana    2300 05/13
efg       #vegetable 0700 04/16

After first 3 letters, i have 9 spaces and after fruit there are no specific fixed space, but it varies accroding to the length of the fruit name.

Now my requirement is like i must get the data like below.
Code:
abc#apple(1200 06/23)
ghj#orange(1500 06/27)
uyt#banana(2300 05/13)
efg#vegetable(0700 04/16)

How can i achieve this ?

Thanks
Jay

Last edited by Franklin52; 06-27-2014 at 11:28 AM.. Reason: Replace (code) tags with [code] tags
# 2  
Old 06-27-2014
try
Code:
nawk '{gsub($3,"("$3,$0); gsub($4,$4")",$0); gsub(" ","",$0); print}' file

# 3  
Old 06-27-2014
Can't just

Code:
akshay@Aix:/tmp$ cat file
abc #apple 1200 06/23
ghj #orange 1500 06/27
uyt #banana 2300 05/13
efg #vegetable 0700 04/16

akshay@Aix:/tmp$ awk '{print $1 $2 "(" $3 , $4 ")"}' file
abc#apple(1200 06/23)
ghj#orange(1500 06/27)
uyt#banana(2300 05/13)
efg#vegetable(0700 04/16)

---------- Post updated at 07:58 PM ---------- Previous update was at 07:56 PM ----------

Quote:
Originally Posted by Makarand Dodmis
try
Code:
nawk '{gsub($3,"("$3,$0); gsub($4,$4")",$0); gsub(" ","",$0); print}' file

This removes space in whole line

---------- Post updated at 07:59 PM ---------- Previous update was at 07:58 PM ----------

and output would be something like this
Code:
abc#apple(120006/23)
ghj#orange(150006/27)
uyt#banana(230005/13)
efg#vegetable(070004/16)

# 4  
Old 06-27-2014
Hi Akshay,

That worked.

Thanks
Jay
# 5  
Old 06-27-2014
have you tried command given by Akshay
Code:
awk '{print $1 $2 "(" $3 , $4 ")"}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove some special ascii character

Hello I have this special caracter after retreving rows from sql server: "....spasses: • Entrem al valort 6050108002811 • El donem..." I would like a sed command to remove it..or just know it's ascii code in order to replace it into my sql sentence.. Hope some one knows how to do that.... (7 Replies)
Discussion started by: ldiaz2106
7 Replies

2. Shell Programming and Scripting

grep to remove blank space

Hi All, Need help to grep blank and copy to file. I have a file in below format dns1dm06_10, dns2dm02_04, dbidub,10000000c9a46d0c gbpuhci,10000000c948b00a ibtur001,10000000c9a1ccda yubkbtp1,10000000c93fec5b I need to copy to all lines which doesn't have wwn >> no-wwn.txt 1... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

3. Shell Programming and Scripting

Remove special character ($) from file names

Hello I've searched here and on the 'net for examples of a script or command line function that will remove the $ character from all file names only that can be done within the directory that contains the file names - which are all html files. ie, I have a directory that contains html files... (6 Replies)
Discussion started by: competitions
6 Replies

4. Shell Programming and Scripting

remove special character from a specific column

Hello , i have a text file like this : A123 c12AB c32DD aaaa B123 23DS 12QW bbbb C123 2GR 3RG cccccc i want to remove the numbers from second and third column only. i tried this : perl -pe 's///g' file.txt > newfile.txt but it will remove the number from... (7 Replies)
Discussion started by: shelladdict
7 Replies

5. Shell Programming and Scripting

Insert a special character $ in place of extra spaces

Hi Experts, I have called some.txt with the following content. oracle HYRDSRVIHUB01 pts/0 TESTIHUB 07-JUN-10 CREATE TABLE TESTIHUB PHONE ... (12 Replies)
Discussion started by: naree
12 Replies

6. Shell Programming and Scripting

remove special character from a textfile

Can any one plse help me writing shell script to removing some special character pattern (like / > -------, / > / > ------- etc....as shown below) from the text file ASAP. / > ------- <tag-normalization tag-name="EXECSERVPRODUCT" read-only="false" part="body"> ... (3 Replies)
Discussion started by: bkc
3 Replies

7. Shell Programming and Scripting

How to insert a character in line in Special condition?

Hi, I have a log file generated by a tool which has the following look : /tmp/releases/directory/datefilename1_release_date.zip /tmp/releases/directory/datefilename2_release_date.zip /tmp/releases/directory/datefilename3_release_date.zip... (8 Replies)
Discussion started by: bhaskar_m
8 Replies

8. Shell Programming and Scripting

Remove box like special character from end of string

Hi All, How to remove a box like special character which appears at the end of a string/line/record. I have no clue what this box like special character is. It is transparent square like box. This appears in a .DAT file at the end of header. I'm to compare a value in header with a parameter.... (16 Replies)
Discussion started by: Qwerty123
16 Replies

9. AIX

How can i replace a character with blank space?

i want a command for my script!!! say file consists of character 123 125 127. i need a query to replace the number 2 with 0 so the output should be 103 105 107. i use unix-aix (8 Replies)
Discussion started by: rollthecoin
8 Replies
Login or Register to Ask a Question