LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 12-21-2011, 02:55 PM   #1
Agustina
LQ Newbie
 
Registered: May 2009
Posts: 15

Rep: Reputation: 0
separate columns in a plain text


Hello!!!

I have a file which first lines look like this :

-rw-r--r-- 1 root root 964855 jun 1 2011 20110601-102800-1306942080.4314.WAV
-rw-r--r-- 1 root root 702840 jun 1 2011 20110601-103711-1306942631.4351.WAV
-rw-r--r-- 1 root root 1167850 jun 1 2011 20110601-124746-1306950466.4844.WAV
-rw-r--r-- 1 root root 319470 jun 1 2011 20110601-125540-1306950940.4886.WAV

I need to obtain the "20110601-102800-1306942080.4314.WAV"
Any idea how can I get it?
I tried cut, but the spaces between the each column is not uniform.

Any help appreciated!
 
Old 12-21-2011, 03:06 PM   #2
jthill
Member
 
Registered: Mar 2010
Distribution: Arch
Posts: 209

Rep: Reputation: 65
past cut there's sed, past sed there's awk or shell scripts, past that there's perl or python. sed's enough to do this, the variable spacing can also exist in filenames so you have to be careful with notions of "columns" or "fields".
 
Old 12-21-2011, 06:12 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5
Posts: 16,086

Rep: Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995
Code:
awk '{print $9}' yourfilenamehere
 
Old 12-22-2011, 10:13 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
That text is obviously the output of ls -l. Note that parsing ls is not a recommended way to get a list of filenames. If there are any filenames with whitespace in them, then it becomes much more difficult to safely extract them.

If you would explain exactly what you are trying to do, then we could probably help you to find a better way to do it.

Finally, please use [code][/code] tags around your code and data, to preserve formatting and to improve readability.
 
1 members found this post helpful.
Old 12-22-2011, 11:36 AM   #5
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
As David the H. pointed out, parsing ls is just a bad idea. Even if you insist on gathering filename data with ls, why not use ls -1, or even unadorned ls?

Even better, use find to gather the full names of files you're interested in. Lookup the -print0 option in the manpage to learn how it may help you collect full names more reliably.
 
Old 12-23-2011, 12:30 AM   #6
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
Quote:
Originally Posted by Agustina View Post
I tried cut, but the spaces between the each column is not uniform.
Actually, this is addressed in the LQWiki article on cut.

Code:
$ tr -s ' ' < foo | cut -d ' ' -f 9
20110601-102800-1306942080.4314.WAV
20110601-103711-1306942631.4351.WAV
20110601-124746-1306950466.4844.WAV
20110601-125540-1306950940.4886.WAV
You are still likely to experience trouble though, for reasons explained in the article linked by David the H..
 
  


Reply

Tags
awk, cut, filename


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I separate columns using sed Basse1 Programming 4 07-01-2010 12:54 PM
calculate the average of cells in columns in separate txt files Mike_V Programming 16 05-16-2009 04:37 AM
How much can I edit in plain text? JosephS Linux - Software 4 04-29-2009 09:08 PM
awk command to merge columns from two separate files into single file? johnpaulodonnell Linux - Newbie 4 01-23-2007 10:10 AM


All times are GMT -5. The time now is 12:01 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration