LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-12-2008, 11:02 AM   #1
zest n zeal
LQ Newbie
 
Registered: May 2007
Posts: 18

Rep: Reputation: 0
Read always strips spaces, can I stop it?


I figure that there isn't a way but how do you keep spaces in a variable when reading them from printf or echo?

What I'm trying to do is remove lines from a text file like this one with a particular time and date.

[HTML]
11/02/08 09:53 adam its mondya test
11/02/08 09:53 server its monday
12/02/08 12:39 andy ok i pick him up the following weekend,
12/02/08 12:41 adam you win 0.10
12/02/08 12:42 adam you win 0.10
09/02/08 13:30 adam its one thirty tomorrow
09/02/08 13:30 server its one thirty tomorrow[/HTML]

The aim is to rewrite the same file without the lines with that particular time and date.
i.e
[HTML]
$ grep -v "09/02/08 13:30" my_file.txt
11/02/08 09:53 adam its mondya test
11/02/08 09:53 server its monday
12/02/08 12:39 andy ok i pick him up the following weekend,
12/02/08 12:41 adam you win 0.10
12/02/08 12:42 adam you win 0.10
[/HTML]

so I try and make a variable to fill in the first grep arguement using read

i.e.,

[HTML]
$ read g< <(printf "$day\t$time")
$ echo $g
$ 09/02/08 13:30
#################### note the tab has been stripped
[/HTML]

and other shell concoctions, but read always strips the tab or spaces out of the variable. I guess awk can do this but I can't figure out how to get awk to do an and statements. I would like to know how to read in spaces any how as that would be useful in the future.

any help much appreciated.

Adam
 
Old 02-12-2008, 12:34 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
I don't think it's the read, I get the same result with a simple
assignment ...
Code:
$ day="09/02/08"
$ time="13:30"
$ echo -e "$day\t$time"
09/02/08        13:30
$ g=$(echo -e "$day\t$time")
$ echo -e $g
09/02/08 13:30
What was the question about awk?! :}



Cheers,
Tink
 
Old 02-13-2008, 08:19 AM   #3
zest n zeal
LQ Newbie
 
Registered: May 2007
Posts: 18

Original Poster
Rep: Reputation: 0
Cool so all commands strip spaces ... hmmm

figured it out, changed dates to "seconds since the start of linux time" in the text file (date with the %s format)

then used awk

cat $schedule | awk '$1 < now { print }' now="$date_in_seconds" > $schedule_now

if that makes any sense, fixed anyhow and thanx
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
black and white strips after install of ubuntu dnz Linux - General 2 08-29-2006 05:18 PM
how to make the Read command handles spaces Kilahchris Linux - Newbie 7 11-06-2004 01:10 PM
Xfree86 divides screen into vertical strips...!? rdsmith4 Linux - Newbie 2 02-19-2004 03:24 PM
Black strips on top res of video lectraplayer Linux - Laptop and Netbook 0 12-03-2003 10:26 PM
C in Linux. The program only read the first line and then stop Linh Programming 2 07-03-2003 05:40 PM


All times are GMT -5. The time now is 08:25 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration