Home
Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Help to identify blank space in a file

Tags
grep, sed, shell scripts, solved

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 04-19-2018
Help to identify blank space in a file

Hello,
I have a dictionary of over 400,000 words with the following structure
Code:
source=target

The database contains single words as well as phrases. To train the data, I need only mappings with out a space i.e. where both source and target do not have any space in between.
I use Ultraedit as my editor and have been using the following regex in Unix to identify a blank space
Code:
^[^ ]+$

Since the database is too large, the editor runs out of memory and cannot store all instances to the clipboard.
Am giving below a small sample text
Code:
هيراآباد=हीरा आबाद
واسڪوڊيگاما=वास्कोडीगामा
کانسواءِ=खांसवाइ/खा सिवाइ
آوازنکي=आवाज़नखे
سانآهي=सान आहे
سڏبوآهي=सॾबो आहे
شڪارڪرڻ=शकार करण
ٺاهيندوآهي=ठाहींदो आहे
ٻولينجو=ॿोलीनजो
ٻولينجي=ॿोलीनजे
ڪنديآهي=कंदी आहे
گئسنجو=गैसन जो
ماموغلام=मामूग़ुलाम
زاهدچانڊيو=ज़ाहिद चांडियो
عطرڪمار=अतुरकुमार
غلاممحي=ग़ुलाममही
گلشيرڪوريجو=गुलशेर कोरीजो
زيرحراست=ज़ीर हिरासत

The script should identify only those entries without a space on either side and store them in a separate file, as in the sample output below
Code:
واسڪوڊيگاما=वास्कोडीगामा
آوازنکي=आवाज़नखे
ٻولينجو=ॿोलीनजो
ٻولينجي=ॿोलीनजे
ماموغلام=मामूग़ुलाम
عطرڪمار=अतुरकुमार
غلاممحي=ग़ुलाममही

A perl or awk script would help. I work in a windows environment.
Many thanks.
# 2  
Old 04-19-2018
Have a look at the -v option of grep:
Code:
grep -vF ' ' your_file

# 3  
Old 04-19-2018
Quote:
Originally Posted by rovf
Have a look at the -v option of grep:
Code:
grep -vF ' ' your_file

True. Still, as a measure of safety i would rule out trailing or leading spaces:

Code:
sed -n '/^[[:blank]]*//;s/[[:blank:]]*$//;/ /!p' > /result/file

I hope this helps.

bakunin
The Following User Says Thank You to bakunin For This Useful Post:
gimley (04-19-2018)
# 4  
Old 04-19-2018
Quote:
Originally Posted by bakunin
True. Still, as a measure of safety i would rule out trailing or leading spaces:
For instance using grep:

Code:
grep -v '[^ ] [^ ]' your_file

The Following User Says Thank You to rovf For This Useful Post:
gimley (04-19-2018)
# 5  
Old 04-19-2018
Many thanks for all your kind help. My broadband connectivity was down all day and hence the delay. All the solutions worked. I had ensured that my data had no trailing spaces so the issue of trailing spaces does not arise but is is nice to have a solution which ensures that trailing spaces are handled.
Thanks once again.
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to identify exact text and then add a blank line above it using sed? jbrass Shell Programming and Scripting 7 06-29-2015 06:33 AM
How to check if the file is empty or has blank space.? Sharma331 Shell Programming and Scripting 10 07-21-2014 05:11 AM
Adding word in blank space kaushik02018 UNIX for Dummies Questions & Answers 9 06-02-2014 05:53 AM
Removing blank space using VI ksgnathan Shell Programming and Scripting 7 12-04-2013 05:58 AM
Remove Space and blank line from file in UNIX shell script Mohin Jain Shell Programming and Scripting 12 09-19-2013 11:28 AM
Not delete space blank Xedrox Shell Programming and Scripting 5 08-23-2013 02:28 PM
Want non-interpretation of blank space using cat muchyog Shell Programming and Scripting 2 08-22-2012 08:16 AM
Removing blank space in file sususa Shell Programming and Scripting 0 07-03-2012 03:09 AM
blank space Reham.Donia UNIX for Dummies Questions & Answers 4 10-04-2011 07:18 AM
String starting with blank space patric2326 Shell Programming and Scripting 5 03-21-2011 09:18 AM
Cut last blank space Aswex Shell Programming and Scripting 7 03-03-2011 07:36 PM
Removing blank lines from comma seperated and space seperated file. pinnacle Shell Programming and Scripting 11 05-08-2009 12:58 PM
Blank Space is not appending in each row of CSV File - Shell Script praka Shell Programming and Scripting 2 05-06-2009 08:25 AM
How can i replace a character with blank space? rollthecoin AIX 8 04-22-2008 09:55 AM
append blank space HAA Shell Programming and Scripting 1 09-03-2007 05:43 AM


All times are GMT -4. The time now is 06:31 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password