Output all data of files into one file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output all data of files into one file
# 1  
Old 10-08-2013
Output all data of files into one file

I have three files (can be more than 3):
cat Katty
=> d4r4ff5rf5
123.44.32.4
=>cat Manu
ffrs44frfrf
123.33.44.3
=>cat Chris
derfe5rgrg
134.4.55.4

So basically, these files are in /Users/Unknown/files/*.
Files can be more than 3. I used 3 just for example.
I want to print out in one file:

host Katty {
code: d4r4ff5rf5;
address: 123.44.32.4
}

host Manu {
code: ffrs44frfrf;
address: 123.33.44.3;
}

host Chris {
code: derfe5rgrg;
address: 134.4.55.4;
}

Code:
path="/Users/Unknown/files/*"
for i in /Users/Unknown/files/*
do
while read line
do
// I dont know how to get the name of file and data of that file (the same in all files)
done
done

# 2  
Old 10-08-2013
Just echo $i or $line and look at the output.
You then will have other questions Smilie
# 3  
Old 10-08-2013
Quote:
Originally Posted by sea
Just echo $i or $line and look at the output.
You then will have other questions Smilie
I did though...But it does not help me lol
# 4  
Old 10-08-2013
1. To get a filename from a given path, you may use the basename utility

2. To read contents of a file, you can use a while loop:
Code:
while read line
do
    echo "$line"
done < /path/to/file

# 5  
Old 10-08-2013
Basically it does not give me contents of the files....I tried it already lol
path=/Users/files/
name (basename, "$path")
echo $name

Gives me error
# 6  
Old 10-08-2013
Code:
path=/Users/Unknown/files/ 
for i in $path/*
do
    echo "Working with file: $i"
    while read line do
        echo "$line"
    done<$i
done

Any clearer?

However, you have to insert this line your own:
grep { -A4 FILE

hth
# 7  
Old 10-08-2013
Quote:
Originally Posted by sea
Code:
path=/Users/Unknown/files/ 
for i in $path/*
do
    echo "Working with file: $i"
    while read line do
        echo "$line"
    done<$i
done

Any clearer?

However, you have to insert this line your own:
grep { -A4 FILE

hth
So sorry... I just copied and run it...but it gives me nothing....Anyway, thanks i will try to fix by myself
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

2. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

Extra data in output file

Gents, I did a small scritp called make_file It read file1.txt file and generate an output as attached.. But the script is showing more extra information not needed. I have attached the output file as desired. Could you please help to fix this scrip to get the correct output Thanks... (4 Replies)
Discussion started by: jiam912
4 Replies

4. Shell Programming and Scripting

Help with add existing file name as new data column in new output file

Input File 1 cat S1.txt MI0043 2731 miR-1 Input File 2 cat S4.txt MI006 310 CiR-1 MI057 10 CiR-24 MI750 5 CiR-24 Desired Output File 1 cat S1.txt.out MI0043 2731 miR-1 S1.txt Desired Output File 2 cat S4.txt.out MI006 310 CiR-1 S4.txt (3 Replies)
Discussion started by: perl_beginner
3 Replies

5. Shell Programming and Scripting

How to output selective delimited data to a new file?

I have the following file which at times can be quite large so can be difficult to read, I need a script that just extracts particular delimited data and outputs to alternate file $cat fix1.log FIX4.4|0=12|55=LIT.L|48=123456|32=5|52=20111107-10:52:22.128|38=100|10=200| ... (6 Replies)
Discussion started by: Buddyluv
6 Replies

6. Shell Programming and Scripting

awk help: Match data fields from 2 files & output results from both into 1 file

I need to take 2 input files and create 1 output based on matches from each file. I am looking to match field #1 in both files (Userid) and create an output file that will be a combination of fields from both file1 and file2 if there are any differences in the fields 2,3,4,5,or 6. Below is an... (5 Replies)
Discussion started by: ambroze
5 Replies

7. Shell Programming and Scripting

How to fill data from other file and get some output

Greetings, I have a hard time creating a large number of user profiles in a database. The data file looks like this : 01/01/80 Mitch Conley . . . . And I need to put the output into: Name: Mitch Surname: Conley Birthday: 01/01/80 Thanks in advance! (3 Replies)
Discussion started by: hemo21
3 Replies

8. Shell Programming and Scripting

split input data file and put into same output file

Hi All, I have two input file and need to generate a CSV file. The existing report just "GREP" the records with the Header and Tailer records with the count of records. Now i need to split the data into 25 records each in the same CSV file. id_file (Input file ) 227050994 232510151... (4 Replies)
Discussion started by: rasmith
4 Replies

9. Shell Programming and Scripting

How to add data from 2 input files and save it in 1 output file

Hi, i have 2 input files which are file1.txt and file2.txt. I need to extract data from file1.txt and file2.txt and save it in file3.txt like example below:- File1.txt ID scrap1 Name scrap1 start 1 end 10 ID scrap2 Name scrap2 start 11 end ... (4 Replies)
Discussion started by: redse171
4 Replies

10. 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
Login or Register to Ask a Question