If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Putting filenames on the same line

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-09-06, 10:46
davidcollins001 davidcollins001 is offline
Registered User
 
Join Date: Feb 2006
Posts: 15
Putting filenames on the same line

Hi,

I am trying to use a script to place some text in a file, then read the filenames from a folder, then follow it all with some more text. So that it end up something like this:

starting_text_here file1 file2 file3 finishing_text

But so far I have only managed to get it so that the files are on the same line, ie:

starting_text_here
file1 file2 file3
finishing_text

I have tried using the multi line stuff in sed but I don't really understand how to use it
Thanks
Reply With Quote
  #2 (permalink)  
Old 03-09-06, 10:56
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool


Please clarify your requirements providing a sample input file(s) and sample result file(s) and the code to your script.

Thanks.

__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 03-09-06, 11:17
davidcollins001 davidcollins001 is offline
Registered User
 
Join Date: Feb 2006
Posts: 15
OK, sorry.

I have a list of files like this in a folder.

90007-01-11-04Z
90007-01-12-00
90007-01-12-00A
90007-01-13-00
90007-01-13-00A
90007-01-13-00Z
90007-01-14-00
90007-01-14-00A
90007-01-14-00Z
90007-01-15-00A

What I want to do is insert a bit of code at the start of the line, then the file names, followed by a different bit of code.
This is the code that I have so far.

#insert combine script
sed '$a\
\
\
\${combi} all' $EXPATH/combine.tmp > $EXPATH/combine


#search folder for name remove unwanted names, place on same line with awk
ls $EXPATH | grep '^'"$FILE"'.*' | grep -v '_' | grep -v '\.' |
awk '{
printf ("../%s ",$1)
}' >> $EXPATH/combine


sed '$a\
-addclusters -nosyst -top\
' $EXPATH/combine > $EXPATH/combine.tmp

I have so far managed to get all the filenames on the same line, but I can't get the code onto the same line

thanks
Reply With Quote
  #4 (permalink)  
Old 03-09-06, 14:22
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool



Your first grep (grep '^'"$FILE"'.*') combined with the the third grep ( grep -v '\.' ) may not work.

I assume you are wanting to list (ls) all file that begin with "$FILE"? excluding those that have an underscore (_) and dot (.).

Do you want the result in the "$EXPATH/combine" file to be something like this???:

-addclusters -nosyst -top ../file1 ../file2 ../file3

Ok try this:
Code:
EXPATH=/path/to/files
FILE='90007'
echo "`ls -1 $EXPATH | grep "${FILE} | grep -v '_' | grep -v '\.' `"|\
awk 'BEGIN{printf "-addclusters -nosyst -top ";}
{printf " ../%s ",$1;}
END {print ";"}
' >> $EXPATH/combine











__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #5 (permalink)  
Old 03-10-06, 03:59
davidcollins001 davidcollins001 is offline
Registered User
 
Join Date: Feb 2006
Posts: 15
Thankyou so much!! You have just removed some of the most cumbersome parts of my code!!

The grep parts appear to work, although I recognise that there may be an issue if I am not careful and there are unwanted filenames without _ or .

Thanks
Reply With Quote
  #6 (permalink)  
Old 03-10-06, 10:37
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool


Glad to help.
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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