Retaining Spaces within a word


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Retaining Spaces within a word
# 1  
Old 09-10-2007
MySQL Retaining Spaces within a word

Hi Experts,

I have a 2 GB flat file which have unicode field, some of them are blanks and its size is 4000 character. In the existing system SED command removes the spaces. Because of this field itself....it is taking almost three days to complete the file processing. I removed sed and used tr command...it worked in less than a minute. Now the challenging part is the character fields have more than one space, I am tr -s ' ' '' to remove the spaces, but it is removing the spaces inbetween the characters which is more than one space.


My sample record is this:

262774372|58959454 | Rajiv Rajiv | tuerueeu | | erueirei
647585858|784783434 | Ramesha Ramesha| tyuu5u4o| | ruieieiei

Earlier following is the command used to remove spaces:

sed s/[[:space]]*|/|/g; s/[ \t]*$//g < File1 > File2

Output was:
262774372|58959454|Rajiv Rajiv|tuerueeu||erueirei
647585858|784783434|Ramesha Ramesha|tyuu5u4o||ruieieiei

Time taken to process file was 3.5 days

Later I added tr command before the sed to remove spaces faster by adding the following

tr -s ' ' '' < File1 > File2
sed 's/[[:space]]*|/|/g; s/[ \t]*$//g;s/^[ \t]*//g;' < File 2 > File3

Output was:
262774372|58959454|Rajiv Rajiv|tuerueeu||erueirei
647585858|784783434| Ramesha Ramesha|tyuu5u4o||ruieieiei

Time taken to process file was less than a minute, since the big spaces are translated faster.

I am not able to retain the spaces between the characters as is, since tr -s will squeeze the space to one space.

The value | Rajiv Rajiv | -> changed to |Rajiv Rajiv|

I have to retain the space.....

Please let me know if you have any workaround...

Thanks,
Rajiv
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Retaining value outside loop

Hi, I m new to shell scripting. I did some research and understand that unix treats while and other loops as new shell and hence the variable loose its value outside of the loop. I found solution for integer variable but in mycase this is a string variable. here variable loc is a... (6 Replies)
Discussion started by: knowyrtech
6 Replies

2. Shell Programming and Scripting

Retaining whitespaces...

There's an input file(input.txt) which has the following details : CBA BA <Please note the second record has a LEADING WHITESPACE which is VALID> I am using the following code to read the content of the said file line by line: while read p ; do echo "$p" done < input.txt This is the... (1 Reply)
Discussion started by: kumarjt
1 Replies

3. Shell Programming and Scripting

How to catch a two word keyword which may contain a new line(may include spaces or tab) in it?

How to catch a two word keyword which may contain a new line(may include spaces or tab) in it. for example there is a file a.txt. $more a.txt create view as (select from ......... .......... ( select .... ( select ...... .. select only no ((( number ( select end (12 Replies)
Discussion started by: neelmani
12 Replies

4. Shell Programming and Scripting

Prevent word splitting with file with spaces in name

Hello, I have a script that "validates" a ZIP file that look like this AAA_20120801.zip => x~back end~20120801.TXT y~time in~20120801.TXT z~heat_chamber~20120801.TXT AAA_20120801.ctlMy task is to compare its contents (i.e the list of files contained inside) with the control file that is... (2 Replies)
Discussion started by: alan
2 Replies

5. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

6. Shell Programming and Scripting

help in retaining leading zero

Hello. I'm trying to add multiple numbers with varying length and with leading zeroes in it. However, I'm getting the sum (totalHashAccountNumber) without the leading zeroes in it. How do I retain the leading zeroes? Please pardon the lengthy code.. I'm getting the hash account number from 2... (2 Replies)
Discussion started by: udelalv
2 Replies

7. Ubuntu

How to remove multiple spaces in between word? (VI EDITOR)?

What last line mode command allows me to remove extra spaces in between words in a text? (1 Reply)
Discussion started by: rabeel
1 Replies

8. Shell Programming and Scripting

Retaining spaces between words

Retaining Spaces within a word -------------------------------------------------------------------------------- Hi Experts, I have a 2 GB flat file which have unicode field, some of them are blanks and its size is 4000 character. In the existing system SED command removes the spaces.... (7 Replies)
Discussion started by: RcR
7 Replies

9. UNIX for Dummies Questions & Answers

how to delete spaces around a word

suppose a line has one word ex: unix how to delete space around that word? (8 Replies)
Discussion started by: sachin.gangadha
8 Replies

10. Shell Programming and Scripting

Retaining Spaces while redirecting output

I need to merge data from more than one file and I am using while read line_record do field1=`echo $line_record | awk -F "," '{ print $1 }'` echo $line_record >> $outFile if then while read new_linerec do echo $new_linerec... (3 Replies)
Discussion started by: skrakesh
3 Replies
Login or Register to Ask a Question