LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-25-2010, 10:48 AM   #16
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556

You are not paying attention to details! You did not set IFS in your second codeblock above. Watch:

Code:
root@reactor: awk -F":" '{OFS=":"; print $1, $2, $3, $4, $5}' TestFile
1::2:3:4
4:5:6:7:8
7:8:9:10:
7: 8 9:1:2:3
root@reactor: IFS=":"; awk -F":" '{OFS=":";print $1,$2,$3,$4,$5}' TestFile | while read one two three four five; do echo "two : $two"; done
two : 
two : 5
two : 8
two :  8 9
root@reactor:
Now, output appears, to me anyway, to be correct. Is it not?
 
Old 10-26-2010, 01:41 AM   #17
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 303

Original Poster
Rep: Reputation: 32
Code:
IFS=":"
awk -F":" '{OFS=":";for(x=1;x<=5;x++){if($x==" "){$x="*"}};print $1,$2,$3,$4,$5}' TrackMsgFile.0806 | while read one two three four five; do
 echo "Here's your vars: '$one' '$two' '$three' '$four' '$five'"
done
solves the issue raised in post #11.
But, could not solve the empty space issue addressed in post #8.

Thanks.
 
Old 10-26-2010, 05:18 AM   #18
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
OK, I thought the empty space issue was addressed by returning the "*" character when a field contains only an empty space. I did however adjust the code in post #10 so that if either a space or an empty field (between two colons) is detected, a "*" is returned.
If this doesn't address any remaining issue, then I'm afraid I'm missing something about this situation. If none of these ideas work, and the ideas presented by the other members in this thread, are of no help either, than it may be a good idea to demonstrate anew the requirements of this problem:

The way I understand it is: you have an input file containing 5 fields, delimetered by colons. Fields might be empty or contain a space (meaning it is empty), but the colon delimiters are always there. You want each of the 5 fields' values returned into a shell variable for processing each time a line from the file is read in. If a space is contained within one of the fields, it doesn't matter, right? I mean, if a field contains "John Smith", would you prefer to have returned "JohnSmith" or "John*Smith"?

So, I thought the requirements have been met. If there's something I've not got right in that, please correct me, and:

--Show us the exact input file.

The part about assigning the fields to the variables, is easy enough; the problem here seems to have to do with spaces, but I don't understand just what that problem is.

Thank you for you patience!

EDIT: Plus, if there's someone else reading this, who sees what I'm missing, by all means, jump in!

Last edited by GrapefruiTgirl; 10-26-2010 at 05:20 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] read from keyboard while reading from file in SHELL SCRIPTING m3ll0 Programming 11 10-30-2010 08:30 AM
shell-scripting.pdf files garethsays Linux - Newbie 2 01-30-2009 06:51 AM
Shell scripting,;problem reading from database and exporting to html sunksullen Programming 7 05-18-2007 02:16 PM
Combine files using shell scripting ccray Linux - Newbie 14 01-12-2006 11:14 AM
Reading text from a file using shell scripting. mrobertson Programming 11 06-29-2005 12:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration