reading multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading multiple files
# 1  
Old 05-04-2009
reading multiple files

Hello

I have a requirement where i have to loop through certain directory which will have multiple files. After looping through i have to make a list of file names exisitng in the directory and write them to a sequental file and each file should be delimited by ^%^

i.e If i have 3 files A, B,C in a directory called Files then i have to loop through the Files directory and write the file names to a .txt file with each file name is delimited by ^%^ as below

A^%^B^%^C

Regards
Dsdev_123
# 2  
Old 05-04-2009
One way:
Code:
cd /directory
ls | awk '{ printf("%s^%%^", $1) }' | sed 's/\^\%\%$//' > /path/to/file.txt

# 3  
Old 05-04-2009
Try this:

Code:
 ls | awk '{printf "%s%s", NR==1?"":"^%^",$0}'

# 4  
Old 05-05-2009
Quote:
Originally Posted by jim mcnamara
One way:
Code:
cd /directory
ls | awk '{ printf("%s^%%^", $1) }' | sed 's/\^\%\%$//' > /path/to/file.txt


Hi when i executed this i am getting
A^%^B^%^C^%^

The last filename should not get ^%^ at the end.

Thanks for your reply
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello, I would like to ask for help with csh script. An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
Discussion started by: FMMOLA
7 Replies

2. Shell Programming and Scripting

Search & Replace in Multiple Files by reading a input file

I have a environment property file which contains: Input file: value1 = url1 value2 = url2 value3 = url3 and so on. I need to search all *.xml files under directory for value1 and replace it with url1. Same thing I have to do for all values mentioned in input file. I need script in unix bash... (7 Replies)
Discussion started by: Shamkamde
7 Replies

3. Shell Programming and Scripting

reading information from a table and apply a command on multiple files

Hey gyuz, I wanna calculate the number of mapped reads of a bam file in a region of interest. I used this code to do so : samtools view input.bam chrname:region1 > region1.txt This will store all the reads from given bam file within the region of interest in region1.txt Now I have... (5 Replies)
Discussion started by: @man
5 Replies

4. Shell Programming and Scripting

Using grep with multiple loops in reading files

I am trying to read a file line by line and then search that line in another file and get a particular column from the second file. I have written this code.but its not working properly #!/bin/sh while read keyword in duplicate.txt do echo $keyword while read line do ... (7 Replies)
Discussion started by: Prachi Gupta
7 Replies

5. UNIX for Dummies Questions & Answers

Reading and writing data to and from multiple files

Hi, I have several text files. One main file contains the detail data, other have some information to extract data from the main file, and some are empty files. Examples are shown below: The main file look like: MainFile.txt >Header1 data1...data1... >Header2 data2...data2... ... ...... (2 Replies)
Discussion started by: Fahmida
2 Replies

6. UNIX for Dummies Questions & Answers

Using AWK: Extract data from multiple files and output to multiple new files

Hi, I'd like to process multiple files. For example: file1.txt file2.txt file3.txt Each file contains several lines of data. I want to extract a piece of data and output it to a new file. file1.txt ----> newfile1.txt file2.txt ----> newfile2.txt file3.txt ----> newfile3.txt Here is... (3 Replies)
Discussion started by: Liverpaul09
3 Replies

7. Shell Programming and Scripting

Search & Replace in Multiple Files by reading a input file

Hi, I have a folder which contains multiple config.xml files and one input file, Please see the below format. Config Files format looks like :- Code: <application name="SAMPLE-ARCHIVE"> <NVPairs name="Global Variables"> <NameValuePair> ... (0 Replies)
Discussion started by: haiksuresh
0 Replies

8. Shell Programming and Scripting

Create Multiple files by reading a input file and changing the contents

Being new to this area .I have been assigned a task which i am unable to do . Can any one please help me . Hi I have requirement where i have input file XYZ_111_999_YYYYMMDD_1.TXT and with header and series of Numbers and Footer. I want to create a mutiple output files with each file having a... (2 Replies)
Discussion started by: bhargavkr
2 Replies

9. UNIX for Dummies Questions & Answers

Ksh Storing Multiple Files and reading each line in each file.

How would I go about storing multiple file paths in a directory that begin like: 20080402* and run a loop that reads each line of each file thats in a given directory. So far this is what I have: #!/bin/ksh echo "ENTER Reprint Date (YYYYMMDD): " read ReprintDate echo ""... (1 Reply)
Discussion started by: developncode
1 Replies

10. Shell Programming and Scripting

Reading multiple tags from .asx files

Hi, I'm trying to wget a series of .asx files, read <title> and <ref> tags from them and then sending that information to wget. asx files contains the following information <ASX VERSION="3.0"> <ENTRY> <STARTTIME Value="00:00:00.0" /> <TITLE>title of the movie</TITLE> <REF... (0 Replies)
Discussion started by: underlig
0 Replies
Login or Register to Ask a Question