LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 09:37 AM   #1
peter7089
Member
 
Registered: May 2016
Posts: 72

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, 09:48 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,987

Rep: Reputation: 1239Reputation: 1239Reputation: 1239Reputation: 1239Reputation: 1239Reputation: 1239Reputation: 1239Reputation: 1239Reputation: 1239
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, 10:27 AM   #3
peter7089
Member
 
Registered: May 2016
Posts: 72

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, 10:31 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ Win10
Posts: 9,493

Rep: Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024
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 10:34 AM.
 
Old 02-03-2017, 10:32 AM   #5
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

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

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

Rep: Reputation: Disabled
Code:
for i in `cat foo`; do bar ; done
 
Old 02-03-2017, 01: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


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

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

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