Adding filename into file content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding filename into file content
# 1  
Old 11-11-2005
Adding filename into file content

Dear Experts,

Please help to teach me how to add the filename into the file content.

Actually the file name are EVENTS-20050912.

***************New output that I want***************
EVENTS-20050912 03:33:37 ALARM: BTSSPAN-277-1 30-18013
EVENTS-20050912 12:10:28 ALARM: BTSSPAN-297-2 30-18013
EVENTS-20050912 20:40:05 ALARM: BTSSPAN-297-1 30-18013
EVENTS-20050912 23:55:27 ALARM: BTSSPAN-277-1 30-18013

**********************************************************

***My original data but didn't have file name into the content ***

03:33:37 ALARM: BTSSPAN-277-1 30-18013
12:10:28 ALARM: BTSSPAN-297-2 30-18013
20:40:05 ALARM: BTSSPAN-297-1 30-18013
23:55:27 ALARM: BTSSPAN-277-1 30-18013
# 2  
Old 11-11-2005
nawk '{$0 = FILENAME OFS $0; print}' myFile
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to prepend filename to its content without a third file?

Hello, Is possibly there a way to prepend the filename to its content without a third file? The reason is to add a header to each file contents to distinguish each other when they are pasted side-by-side. sample.txt: XLOC_001 0 XLOC_002 23 XLOC_003 4 XLOC_012 6output (with the same... (4 Replies)
Discussion started by: yifangt
4 Replies

2. Shell Programming and Scripting

Adding filename and line number from multiple files to final file

Hi all, I have 20 files (file001.txt upto file020.txt) and I want to read them from 3rd line upto end of file (line 1002). But in the final file they should appear to start from line 1. I need following kind of output in a single file: Filename Line number 2ndcolumn 4thcolumn I... (14 Replies)
Discussion started by: bioinfo
14 Replies

3. Shell Programming and Scripting

Adding content of two file in a single file column wise

Hi, I am trying to get the file in particular pattern using shell script. I have to add one column to some other file. For example consider two file as below. File1: name1 name2 name3 File2: Add1 age1 Add2 age2 Add3 age3 I want this two file in a single file format something like... (3 Replies)
Discussion started by: diehard
3 Replies

4. UNIX for Dummies Questions & Answers

Adding the content of file in another one...

This might be a weird question, that's not possible, but just wondering: If I have a file for example that has the content: awk '{print "head - "$1" > reduce_lines_"$1}' all And another file that has the content: 221 Is there a way to put the 221 in the space (after head -) of... (27 Replies)
Discussion started by: cosmologist
27 Replies

5. Shell Programming and Scripting

Adding filename to each line of the file

Hi, I am a relative new bee in scripting. I need to develop a script such that the code would iterate through each file in a source directory and append every line of the file with '|' and the corresponding file filename. eg INPUT file IF927_1.dat - H|abc... (4 Replies)
Discussion started by: scripting_newbe
4 Replies

6. Shell Programming and Scripting

Search for string in filename, not file content

How can I search for a string in a filename? For example, I want to know if a filename (not the file contents) contains the string "test". (3 Replies)
Discussion started by: daflore
3 Replies

7. Shell Programming and Scripting

Grabing Date from filename and adding to the end of each line in the file.

Hi, I have 24 .dat files something like below. The file name starts with “abc” followed by two digit month and two digit year. Is there a way to grab the month and year from each filename and append it to the end of each line. Once this is done I want to combine all the files into file... (1 Reply)
Discussion started by: rkumar28
1 Replies

8. Shell Programming and Scripting

How to adding the filename into file contents

Dear Experts, Please help to teach me how to add the filename into the file content so that i can get the output below:- Actually the file name ***************New output that I want*************** =====2005-11-12===== EVENTS-20050912 03:33:37 ALARM: BTSSPAN-277-1 30-18013... (2 Replies)
Discussion started by: missutoomuch
2 Replies

9. UNIX for Dummies Questions & Answers

find filename based on file content

:confused: There is a flat file on my system which contains email addreses of people in my company. This file is utilized when sending notifications for various things. However nobody knows where this file is located or what it is named. The only thing we know is the email address of a user who... (4 Replies)
Discussion started by: kollerj
4 Replies
Login or Register to Ask a Question