LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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-03-2017, 08:37 AM   #1
peter7089
Member
 
Registered: May 2016
Distribution: MX Linux
Posts: 249

Rep: Reputation: Disabled
'ls' content from text file?


Is it possible to list content from text file? Fro example, if the text file contains something like this:

Code:
/etc/mysql
/etc/init.d/mysql
/etc/apparmor.d/abstractions/mysql
/var/lib/php5/modules/apache2/enabled_by_maint/mysql
/var/lib/php5/modules/registry/mysql
/var/lib/php5/modules/cli/enabled_by_maint/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/var/log/mysql
/usr/lib/mysql
/usr/lib/perl5/DBD/mysql
/usr/lib/perl5/auto/DBD/mysql
/usr/bin/mysql
/usr/share/phpmyadmin/js/codemirror/mode/mysql
/usr/share/php5/mysql
/usr/share/mysql
/usr/share/dbconfig-common/internal/mysql
/usr/share/dbconfig-common/data/phpmyadmin/upgrade/mysql
/usr/share/dbconfig-common/data/phpmyadmin/install/mysql
/usr/share/javascript/codemirror/mode/mysql
/usr/share/bash-completion/completions/mysql
Is it possible to implement something like "ls < text_file.txt" that will list the files and directory information for the lines in the file?
 
Old 02-03-2017, 08:48 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by peter7089 View Post
Is it possible to implement something like "ls < text_file.txt" that will list the files and directory information for the lines in the file?
I can think of 2 ways to do this.
  1. xargs
  2. Write a script
 
Old 02-03-2017, 09:27 AM   #3
peter7089
Member
 
Registered: May 2016
Distribution: MX Linux
Posts: 249

Original Poster
Rep: Reputation: Disabled
I think i found a way: ls -al `cat text_file". It seems to do what i want.
 
Old 02-03-2017, 09:31 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
try this
Code:
grep -rnw '/path/to/somewhere/' -e "pattern"
you want to make a list of files within a different file that has their path to them from files only containing given text within the files themselves?

find
grep
redirection >

helpers
xargs
-print0

I'd have to experiment myself until I figured that out.

Last edited by BW-userx; 02-03-2017 at 09:34 AM.
 
Old 02-03-2017, 09:32 AM   #5
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
while read -r line; do ls -al "$line"; done < text_file

Last edited by szboardstretcher; 02-03-2017 at 10:57 AM. Reason: missing quotes
 
1 members found this post helpful.
Old 02-03-2017, 10:40 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
for i in `cat foo`; do bar ; done
 
Old 02-03-2017, 12:46 PM   #7
nodir
Member
 
Registered: May 2016
Posts: 222

Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
Code:
for i in `cat foo`; do bar ; done
Nah, not like that: http://mywiki.wooledge.org/BashPitfa...8ls_.2A.mp3.29
What szboardstretcher said
http://mywiki.wooledge.org/BashFAQ/001
 
  


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] Replacing text with content from another file in an order Sayan Acharjee Programming 6 06-17-2016 02:26 PM
Want to transpose the text file content sekaranarun Linux - Newbie 1 09-03-2013 06:18 AM
php script that reads content from text file adrianno2 Programming 3 07-21-2008 01:14 AM
Replace text of unknown content with other text in file brian0918 Programming 15 07-14-2005 09:22 PM
Replace text of unknown content with other text in file brian0918 Linux - Software 1 07-14-2005 03:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:41 AM.

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