LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2002, 03:15 AM   #1
FredrikN
Member
 
Registered: Nov 2001
Location: Sweden
Distribution: GNU/Linux since -97
Posts: 149

Rep: Reputation: 15
Question input from a file ??


Hi.
Maybe someone can help me with this problem.
Let say I want to run the command cat test.txt grep -v
and then I want to get the rest of the command from some textfile.

I tried
cat test.txt grep -v < textfile.txt

and there are many lines in the textfile
that looks like this
192.168.0.1
192.168.0.2
192.168.0.3

I know I can do this with perl or C but it will be much quicker and easier if the < stuff will work.

Maybe someone can help me with this problem ?

Thanks.
 
Old 03-29-2002, 04:28 AM   #2
Manish
Member
 
Registered: Feb 2002
Distribution: Debian / Debian-based
Posts: 58

Rep: Reputation: 15
cat test.txt | grep -v `cat textfile.txt`

Note that ` character is the one besides the top numeric 1 key (below Escape key).

I have not tested it, but hope it works.
 
Old 03-29-2002, 05:36 AM   #3
FredrikN
Member
 
Registered: Nov 2001
Location: Sweden
Distribution: GNU/Linux since -97
Posts: 149

Original Poster
Rep: Reputation: 15
Smile

Thanks, works great )

I have one more question about this.

If the textfile looks like this, it's a file with user and their passwords and home dirs.
E.x.

cool -p hithere -b /home/xxx/
fast -p fast -b /home/xxxx/

So if I run
useradd `cat usersfile.txt`
there can only be one user in the textfile.

Is it possible to run the useradd command for each line in the textfile.

I wrote a perl script for this a year ago, but if it could be solved with this stuff I'm talking about it would be great :-)

Thanks

Last edited by FredrikN; 03-29-2002 at 05:39 AM.
 
Old 03-29-2002, 07:49 AM   #4
Manish
Member
 
Registered: Feb 2002
Distribution: Debian / Debian-based
Posts: 58

Rep: Reputation: 15
I guess the best tool to use in this case is awk. See the man page for awk to see what parameters to use to execute a command with every line of a text file.
 
Old 03-30-2002, 12:25 AM   #5
FredrikN
Member
 
Registered: Nov 2001
Location: Sweden
Distribution: GNU/Linux since -97
Posts: 149

Original Poster
Rep: Reputation: 15
Thanks.
awk was the right tool.

Works fine now :-)

//FredrikN
 
Old 03-30-2002, 12:53 AM   #6
Manish
Member
 
Registered: Feb 2002
Distribution: Debian / Debian-based
Posts: 58

Rep: Reputation: 15
cool.
 
  


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
File Input, how to get number of items? ftgow Programming 1 03-11-2005 01:31 AM
PHP: No input file specified pembo13 Linux - General 0 10-03-2004 09:49 PM
Having rm or mv take file input BlueOrb Linux - Newbie 4 06-29-2004 09:42 PM
C++ binary file input CamelofCamelot Programming 1 12-28-2003 06:38 PM
input file to htpasswd igcsteve Linux - Newbie 4 06-05-2003 12:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:47 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