LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   'ls' content from text file? (https://www.linuxquestions.org/questions/linux-newbie-8/ls-content-from-text-file-4175598894/)

peter7089 02-03-2017 08:37 AM

'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?

TenTenths 02-03-2017 08:48 AM

Quote:

Originally Posted by peter7089 (Post 5664474)
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

peter7089 02-03-2017 09:27 AM

I think i found a way: ls -al `cat text_file". It seems to do what i want.

BW-userx 02-03-2017 09:31 AM

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.

szboardstretcher 02-03-2017 09:32 AM

while read -r line; do ls -al "$line"; done < text_file

Habitual 02-03-2017 10:40 AM

Code:

for i in `cat foo`; do bar ; done

nodir 02-03-2017 12:46 PM

Quote:

Originally Posted by Habitual (Post 5664541)
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


All times are GMT -5. The time now is 02:19 PM.