LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 06-16-2015, 06:00 PM   #1
HonestTea
LQ Newbie
 
Registered: Jun 2015
Posts: 2

Rep: Reputation: Disabled
Smile Select specific characters from line


Hello All!

This is my first time posting on this site.

I'm putting together a script that unlocks selected files. I've gotten the script to allow me to select files and/or folders and run the unlock command recursively. I now what to limit users from, let's say, unlock folders from msdos formatted volumes. I can get that filter from the "mount" command and parsing that.

My issue is that when the user selects the files and/or folders the list gets outputted to a file and I can't seem to parse out only the first three slashes of each line.

ex.
if output_file1 has lines:

/Volume/test/file1.txt
/Volume/test/folder1/folder2/folder3/file2.txt
/Volume/orange/folder1/file3.txt

I want to create a loop that grabs each line, only pulls the "/Volume/test/" part of each line, runs the "mount" command with the output, then checks if the returned value of | grep msdos is true"

I can figure out everything except how to grab the "/Volume/test/" of each line. I was thinking something that would allow me to print each line up to the third "/" maybe.

any help would be greatly appreciated.
 
Old 06-16-2015, 06:18 PM   #2
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by HonestTea View Post
any help would be greatly appreciated.
Are you working in a Linux environment?

Daniel B. Martin
 
Old 06-17-2015, 11:40 AM   #3
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,152

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Code:
echo $x|awk -F "/" '{print "/" $2 "/" $3}'
 
Old 06-17-2015, 06:30 PM   #4
HonestTea
LQ Newbie
 
Registered: Jun 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
danielbmartin - yeah I'm working in a mixed Mac and Linux environment.

---------- Post added 06-17-15 at 07:31 PM ----------

Keith Hedger - Thanks a million! That worked like a charm. I couldn't figure out the right awk parameters.
 
Old 06-17-2015, 08:46 PM   #5
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by HonestTea View Post
... I'm working in a mixed Mac and Linux environment.
I like to use cut for this task.

With this InFile ...
Code:
/Volume/test/file1.txt
/Volume/test/folder1/folder2/folder3/file2.txt
/Volume/orange/folder1/file3.txt
... this cut ...
Code:
cut -d/ -f1-3 $InFile
... produced this result ...
Code:
/Volume/test
/Volume/test
/Volume/orange
Daniel B. Martin
 
  


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] Need help in replacing set of characters in a specific line using sed or awk bbachu Programming 15 01-03-2011 01:01 AM
[SOLVED] Bash script to parse a file to get a set of line between a specific characters venkatrg Linux - Newbie 5 12-24-2010 06:55 AM
[SOLVED] change a specific characters to capital in a specific text ramzaher Linux - Newbie 12 12-03-2010 04:50 AM

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

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