Find fields with no spaces in value


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find fields with no spaces in value
# 8  
Old 04-18-2007
Hi Deepak,

Thanks for your reply.

but i did not fully get you.

Do u mean to say that i should do like this?

while read line
do
str=`echo $line | awk '{split($0, date,"|"); print date[2]"|"date[3]"|"date[4]"|"date[5] }'`

export IFS=" "

for j in `cat uniqfile | egrep "${str}"`
do
echo $j
done

awk ' NF > 0 ' uniqfile

done<difffile


OR

while read line
do
str=`echo $line | awk '{split($0, date,"|"); print date[2]"|"date[3]"|"date[4]"|"date[5] }'`

export IFS=" "

for j in `awk ' NF > 0 ' uniqfile` ## but where are we grepping the string for?
do
echo $j
done

Thanks a million , Mike


done<difffile
# 9  
Old 04-18-2007
This should take care of it:

Code:
awk "/${str}/ && NF > 0 " txt.txt

I had put the IFS/for blocks in to demonstrate how reassigning IFS would work, but my recommendation is to not reassign IFS unless absolutely necessary.

EDIT: Fixed!

Last edited by DeepakS; 04-18-2007 at 04:50 PM..
# 10  
Old 04-18-2007
Looking at this again, the awk script is producing inconsistent results. You may need to resort to using this for the time being:

Code:
export IFS="
"

for j in `cat uniqfile | egrep "${str}"`
do echo $j
done

Do read up on IFS, though as it can be dangerous to change IFS.

I'll look at this later to see if I can work out a better awk script (or perhaps some awk expert can interject)
# 11  
Old 04-18-2007
Thanks a lot Deepak.

Vgersh helped me in doing my task with awk command.

to find and group records in file. Please have a look at this thread for more in detail.

Thanks again for your help.

Regards, Mike
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Find and rm files with spaces in the name

I'm sure this has been answered before, but my searches have not turned up the right solution. :confused: I need to remove files in a directory, without descending into subdirectories, older than n days. Some of the filenames contain spaces or other special characters: E10403 (2) E20402 (2)... (15 Replies)
Discussion started by: Papa Lee
15 Replies

2. Shell Programming and Scripting

How to preserve spaces in input fields with awk?

I'm trying to do something pretty simple but its appears more complicated than expected... I've lines in a text file, separated by the comma and that I want to output to another file, without the first field. Input file: file1,item, 12345678 file2,item, 12345678 file2,item, ... (8 Replies)
Discussion started by: Armoric
8 Replies

3. Shell Programming and Scripting

Cutting fields from lines with multiple spaces

Please see the following code, between "status" and "OK" exists many spaces, I want to get status OK . how to ignore multi spaces? If tab exists in the spaces, how to ignore it ? Is there other commands can replace cut? $ echo 'drv status OK'| cut... (3 Replies)
Discussion started by: 915086731
3 Replies

4. Shell Programming and Scripting

How to Use Sed Command to replace white spaces with comma from between two fields - Mayank

SHELL SCRIPT Hi I have a file in the following format Mayank Sushant Dheeraj Kunal ARUN Samir How can i replace the white space in between and replace them with a comma?? The resultant output should be Mayank,Sushant Dheeraj,Kunal ARUN,Samir i tried using sed -e... (8 Replies)
Discussion started by: mayanksargoch
8 Replies

5. Shell Programming and Scripting

awk ignores fields with only spaces or empty

Hi, Does any one know how to avoid the scenario where awk ignores the fields having only spaces or empty fields? for instance, Data: "a","b","c","d",""," " code: awk -F, '{ print NF }' File the output I get is 4 instead of 6 do you know how to avoid this? (6 Replies)
Discussion started by: ahmedwaseem2000
6 Replies

6. Shell Programming and Scripting

remove blank spaces from fields

Hi Friends, I have large volume of data file as shown below. Beganing or end of each filed, there are some blank spaces. How do I remove those spaces? AAA AAA1 | BBB BB1 BB2 |CC CCCC DDDD DD | EEEEEEE EEEEEEEE | FFF FFFFFF FFFF GG GGGGGG |HH HH ... (3 Replies)
Discussion started by: ppat7046
3 Replies

7. Shell Programming and Scripting

remove extra spaces between fields

Hi, I have a source file as mentioned below: I want to remove all the extra spaces between the fields. a b--------|sa df-------|3232---|3 sf sa------|afs sdf-----|43-----|33 a b c------|adfsa dsf---|23-32|23 *Here '-' idicates spaces Now, I want output as below: a b|sa df|3232|3... (7 Replies)
Discussion started by: srilaxmi
7 Replies

8. Shell Programming and Scripting

How can i remove spaces in between the fields in a file

Hey , I have a file and it's having spaces for some of the fields in it. Like the one below. I want to remove the spaces in them through out the file. The spaces occur randomly and i can't say which field is having space. So please help. Here is sample file with spaces after 5th field. (3 Replies)
Discussion started by: dsravan
3 Replies

9. Shell Programming and Scripting

Delete spaces in between fields

I am new to unix and need some assistance. I have a file in the format below with about 15 fields per each record. I have 2 records displayed below. "1234","Andy ","Rich ","0001","123 Main Street ","Dallas " "2345","Andrew ","Richter ","0002","234 First Ave ... (12 Replies)
Discussion started by: guiguy
12 Replies

10. Shell Programming and Scripting

align several fields and fill spaces with zero

hi all, i have a big problem, and i donīt know what to do. i have a flat file with several fields, which are separated by ";" like this: 5656838-7B;97030000-7;*;V16106133 ;1;1; 4612062-0B;97030000-7;*;C14038149 ;1;2; 8044938-0B;97030000-7;*;V16034219 ;1;2; where B is a blank space. ... (2 Replies)
Discussion started by: DebianJ
2 Replies
Login or Register to Ask a Question