LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 05-11-2006, 08:50 AM   #1
bob_man_uk
Member
 
Registered: Jul 2003
Location: uk
Posts: 80

Rep: Reputation: 16
using commands to output path, filename and info to a txt file


ok, this might be a bit difficult but here goes

I have a directory, say /file

in said directory there are aprox 20 files with the structure soXXXXXX.xml where XXXXXX is a number

what i need is to list all these files with their path and with XXXXXX right next to it

For Example

123456 /so123456.xml

Or better yet, seperate the two by pipe "|" and ending with a pipe

123456|/so123456.xml|

i can get the list of the files with find

find ./ -name "so*.xml" -print > list.txt

but that just gives ./so123456.xml,

i'd need to strip out the . at the start and then take the 123456 out of the line, which i havent got a clue how to do then add a | in the middle.

any ideas?

thanks in advance

Matty G
 
Old 05-11-2006, 09:37 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
Code:
find ./ -name "so*.xml" | awk '{{sub(/^\./, "", $0); match($0, /so(.*)\.xml/, arr); print arr[1] "|" $0 "|"}'

Last edited by acid_kewpie; 05-11-2006 at 09:39 AM.
 
Old 05-11-2006, 11:37 AM   #3
bob_man_uk
Member
 
Registered: Jul 2003
Location: uk
Posts: 80

Original Poster
Rep: Reputation: 16
and this is supposed to be run from the command line correct?

i get

Quote:
awk: cmd. line:1: ^ unexpected newline or end of string
the unexpected newline is actually pointing at the 1
 
Old 05-11-2006, 03:31 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
hmm... ok. well i tested it doing an "echo ./so12345.xml | awk ..." so i guess the find output is different. i'm sure you can tweak it ;-)
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirecting output into a filename pbickerd Linux - Software 10 02-24-2006 03:41 PM
how to seperate filename from path in perl mengle Programming 2 08-28-2005 02:35 AM
mapping a key to output txt while in x using term MadPenguin Linux - Software 0 06-22-2005 03:10 PM
how do i get the path of the filename linuxzouk Programming 25 06-10-2004 09:00 AM
use date as output filename? wijnands Linux - Newbie 1 05-12-2004 04:39 PM


All times are GMT -5. The time now is 06:44 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration