Filename (concat) head -1 > newfilelist


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filename (concat) head -1 > newfilelist
# 1  
Old 07-08-2011
Power Filename (concat) head -1 > newfilelist

Gurus. Would appreciate your help very much.

I would like to list all the files in directory, and concat the header record in each file with the filename, and output that list to a filelist.

ie.

filename|header{filename}

Thanks in advance
# 2  
Old 07-08-2011
Try:
Code:
for i in *; do awk 'NR==1{print FILENAME"|"$0}' $i >> filelist; done

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 07-08-2011
Code:
for FILE in *
do
        printf "%s|" "$FILE"
        head -n 1 "$FILE"
done > listfile

This User Gave Thanks to Corona688 For This Post:
# 4  
Old 07-08-2011
thanks guys. Is something like this possible with the above requirement?
Code:
ls *.dat -exec printf {"$file" head -n 1 "$file"} > listfile.lst \;


Last edited by Franklin52; 07-08-2011 at 03:01 PM.. Reason: Please use code tags
# 5  
Old 07-08-2011
If you want to process only *.dat files, then this will do:
Code:
for i in *.dat; do awk 'NR==1{print FILENAME"|"$0}' $i >> listfile.lst; done

This User Gave Thanks to bartus11 For This Post:
# 6  
Old 07-08-2011
Quote:
Originally Posted by sats2059
thanks guys. Is something like this possible with the above requirement?
I don't think ls works that way.

You could just put *.dat instead of * in my code.
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 07-08-2011
MySQL

Works great. Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Concat data

All, I have 2 files A and B with some data. Now i want to concat data from both the files in to 3rd file.Please help me with a single command line. A--123456789 B--jlsjdfkajsjas output file C should be 123456789,jlsjdfkajsjas (2 Replies)
Discussion started by: kiranparsha
2 Replies

2. Shell Programming and Scripting

Concat name

Hi, I need help to combine the first 7 character of firstname if it is longer than 7and combine with the first character of lastname. ex: username lastname => usernaml user lastname => userl Thanks in advance. (10 Replies)
Discussion started by: xitrum
10 Replies

3. Shell Programming and Scripting

How to concat columns?

Hello All, I have a file with following data. 1365787116 3.0 contracts/Procs_Val_Req_forContrct_Amnd_BPEL 1348791394 2.0 contracts/Procs_Val_toTerm_Ret_Contrct_BPEL 1348791394 2.0 contracts/Qualfy_BP_forNew_Ret_Contrct_BPEL 1348791394 2.0 ... (8 Replies)
Discussion started by: Vikram_Tanwar12
8 Replies

4. Shell Programming and Scripting

Concat required

Hi Folks The below is code is giving me value 30. cal | sed '/^$/d' | tail -1 | awk '{printf $NF-1}' Actually the text is like below. echo "you should reply on 30-Jan-2013 evening EST. Here how should i con-cat above logic in that text? (1 Reply)
Discussion started by: coolboy98699
1 Replies

5. Shell Programming and Scripting

Concat

Hi All, My Input file contains: Input.txt Name|Marks ABC|10 GHI|10 JKL|20 MNO|20 PQR|30 Output.txt MARKS|NAME 10|ABC,GHI 20|JKL,MNO 30|PQR Thanks in advance (4 Replies)
Discussion started by: kmsekhar
4 Replies

6. Shell Programming and Scripting

wget same filename from subdirectories and rename or concat

I would like to wget a file "index.html" from a site which is lies in different subdirectories and is different in size. The index.html shall be concatenated or renamed to index01.html index02.html .... I would like to store this file in just one directory and use the option -nd. Though i can't get... (0 Replies)
Discussion started by: sdf
0 Replies

7. UNIX for Dummies Questions & Answers

"tail -n 1 filename" error while "head -n 1 filename" is ok?

Hi all, I was wondering why tail -n 2 filename produce an error when I manage to do similar command on head -n 2 filename SunOS{type8code0}: tail -n 2 filename usage: tail ] tail ] (2 Replies)
Discussion started by: type8code0
2 Replies

8. Shell Programming and Scripting

concat 3 files

Hello Unix gurus, how to concat 3 files content side by side . i have 3 files more report1.txt select *from tab1 A JOIN tab1 B ON more report2.txt A.PK1=B.PK1 where more report3.txt A.AAA <> B.AAA or A.BBB <> B.BBB or A.CCC<> B.CCCC or .. .. .. A.ZZZ <> B.ZZZ; if i concatinate... (3 Replies)
Discussion started by: kanakaraju
3 Replies

9. Shell Programming and Scripting

Awk Concat

Hi All this may be somewhere in internet , but couldnt find the it. i have file as abc01 2010-07-01 12:45:24 2010-07-01 12:54:35 abc02 2010-07-01 12:59:24 2010-07-01 01:05:13 abc03 . . . the output using awk should look like this abc01|2010-07-01 12:45:24|2010-07-01 12:54:35... (3 Replies)
Discussion started by: posner
3 Replies

10. Shell Programming and Scripting

Concat

HI all, How to concat two strings in Shell scrpits suppose x=a y=b i want to display it as ab How to do it ? Thanks.. (1 Reply)
Discussion started by: dhananjaysk
1 Replies
Login or Register to Ask a Question