awk to insert a files names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to insert a files names
# 1  
Old 05-23-2012
awk to insert a files names

I have a couple of text files
which are named as
Code:
1.txt
2.txt
1000.txt
11.txt

I want to cat/merge the contents of each text file into one single file like this
Code:
1
content of 1.txt
2
content of 2.txt
1000
content of 1000.txt
11
content of 11.txt

I can merge the files and insert a space between the contents of the files using the awk
Code:
awk 'FNR==1{print ""}1' *.txt

But would like to know how to modify the above awk command to include the file names (numbers) at the space between merged files.

Please let me know
# 2  
Old 05-23-2012
Code:
awk 'FNR==1{print FILENAME} 1' *.txt

Try that
# 3  
Old 05-24-2012
Code:
$ more *.txt > outfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

2. UNIX for Dummies Questions & Answers

awk question - print columns with names

I found this command and would like to know what it means: gawk 'NR==1{for(i=1;i<=NF;i++)if($i~/FE/)f=i}{for(i=0;i<n;i++)printf"%s%s",i?" ":"",$f;print""}' It seems to mean if the row =1 assign i to that row, and then if FE is in the top row /column then increment and print the row. I am... (2 Replies)
Discussion started by: newbie2010
2 Replies

3. Shell Programming and Scripting

Printing names using awk?

Mike Harrington:(510) 548-1278:250:100:175 Christian Dobbins:(408) 538-2358:155:90:201 Susan Dalsass:(206) 654-6279:250:60:50 Need to learn how to print each record preceded by the number of the record using awk. awk -F '|' '{print NF}'would it be... (2 Replies)
Discussion started by: JA50
2 Replies

4. Shell Programming and Scripting

check if the insert statement is using column names

Hi, Input- a file comtaining a procedure or function with various statements in that one of the statement would be insert into table1 (a,b,c) values (1,2,3) ourput required true if insert statement is using column name (a,b,c) else false. Please suggest (8 Replies)
Discussion started by: manasa_vs
8 Replies

5. UNIX for Dummies Questions & Answers

merge files along with file names (awk)?

Dear programmers, I have a question about conditionally merging multiple files and having their file names in the first column. Input files: file.1.extension file.2.extension file.3.extension file.4.extension ... file.1000.extension where each file looks like this (with multiple lines):... (5 Replies)
Discussion started by: wei.deng
5 Replies

6. Shell Programming and Scripting

how to copy files followed by list of names of all the files in /etc?

....... (2 Replies)
Discussion started by: pcbuilder
2 Replies

7. Shell Programming and Scripting

Assign 1,2,3 according to the names using Awk

Print same letters as 1 or 3 (ex:a/a)and different letters as 2 (ex:a/b) based on Name and subname 1st column indicates main names (ex: ID1 is one main name) and 2nd column indicates sub names (ex: a1 is a subname of ID1) and 3rd column indicates sub-sub names (ex: a/b is a sub-sub name of... (6 Replies)
Discussion started by: ruby_sgp
6 Replies

8. Shell Programming and Scripting

Changing file names with AWK

Dear All, I have some thousands of files in a folder and i need to change those file names without opening the file (no need to change anything in the file content, need to change the file name only). The filenames are as follows: Myfile_name.1_parameter Myfile_name.2_parameter... (6 Replies)
Discussion started by: Fredrick
6 Replies

9. Shell Programming and Scripting

Insert file names when concatenate files into a file

Hi I found the following line would concatenate all test_01 test_02 test_03 files into "bigfile". cat test_* >> bigfile But, what I'm looking for a way to insert each file names in order when concatenated in "bigfile". Thank you samky2005 (2 Replies)
Discussion started by: samky2005
2 Replies

10. Shell Programming and Scripting

awk computed variable names

Is there a way to do make-style computed variable names in awk? e.g. in make foo = bar bar = wocket I can get "wocket" with $($(foo)) Alternatively can you list all defined variables in awk? thanks (4 Replies)
Discussion started by: craig06y
4 Replies
Login or Register to Ask a Question