Print filename with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print filename with awk
# 1  
Old 02-27-2012
Print filename with awk

I can got the filename with this script. it's only show "-" in result.

Code:
cut -d , -f7  CSV_d.*  | awk 'OFS=":"{print FILENAME,substr($1,1,8),substr($1,9,2),substr($1,11,2),substr($1,13,2)}' | sort |uniq

# 2  
Old 02-27-2012
Assuming your 7th field in the csv file does not contain any white space:


Code:
awk 'OFS=":"{print FILENAME,substr($7,1,8),substr($7,9,2),substr($7,11,2),substr($7,13,2)} FS=,  CSV_d.* | sort |uniq

(Not tested, since no sample files put. )

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 3  
Old 02-27-2012
Quote:
Originally Posted by guruprasadpr
Assuming your 7th field in the csv file does not contain any white space:


Code:
awk 'OFS=":"{print FILENAME,substr($7,1,8),substr($7,9,2),substr($7,11,2),substr($7,13,2)} FS=,  CSV_d.* | sort |uniq

(Not tested, since no sample files put. )

Guru.

Thanks you , working welll
Code:
awk -F, 'OFS=":"{print FILENAME,substr($7,1,8),substr($7,9,2),substr($7,11,2),substr($7,13,2)}'   CSV.* | sort |uniq

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to print filename words along with delimiter

Hi, I have filename as: 010020001_S-FOR-Sort-SYEXC_20180109_062320_0100.x937 I need first 5 words of my filename along with the respective delimiters: I tried this: f=010020001_S-FOR-Sort-SYEXC_20180109_062320_0100.x937 echo $f | awk -F '' '{print $1$2$3$4$5}' 010020001SFORSortSYEXC ... (11 Replies)
Discussion started by: gnnsprapa
11 Replies

2. Shell Programming and Scripting

Use while loop to read file and use ${file} for both filename input into awk and as string to print

I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix. I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice. Files:... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

3. Shell Programming and Scripting

Print filename and last line using awk

Hi, using awk command I want to print filenames and the last line of each file, in a single command line statement. I want to use 'awk', because I want to add more functionality to this logic later. I tried the following on *.sh files in the current directory find . -type f -name "*.sh"... (26 Replies)
Discussion started by: ysrini
26 Replies

4. UNIX for Dummies Questions & Answers

grep pipe filename print issue

uname -a SunOS mypc 5.10 Generic_141414-07 sun4v sparc SUNW,SPARC-Enterprise-T2000 uname -a SunOS mypc 5.10 Generic_144488-07 sun4v sparc SUNW,SPARC-Enterprise-T5220 find . -name "*.cer" -exec keytool -v -list -printcert -file {} \; | grep -i "Aug 03" Valid from: Mon Jan 29 00:00:00 GMT... (16 Replies)
Discussion started by: shifahim
16 Replies

5. Shell Programming and Scripting

Howto Print File Path or Print the Filename

I'm trying to clean up my samba share and need to print the found file or print the path of the image it tried to searched for. So far I have this but can't seem to get the logic right. Can anyone help point me in the right direction? for FILE in `cat list`; do if ; then ... (1 Reply)
Discussion started by: overkill
1 Replies

6. Shell Programming and Scripting

Print filename inside loop

Im want to print filename inside loop .. the code im using :- Filename_1=abc_20090623_2.csv.lk Filename_2=def_20090623_2.csv.lk i want to extract filename till .csv eg Filename_1=abc_20090623_2 Filename_2=def_20090623_2 How can i do this inside the for loop ... (3 Replies)
Discussion started by: r_t_1601
3 Replies

7. Shell Programming and Scripting

print the filename

#!/bin/ksh for files in `ls *.gz` do gunzip -c $files | awk -v s=$files -F\" '{print s","$6}' done I have tried FILENAME parameter but it did not work please help. (1 Reply)
Discussion started by: harshakirans
1 Replies

8. AIX

split a filename and print to 2 different headings

I need help to split a filename 'a0crk_user:A0-B0123$#%test' into a0crk_user and A0-B0123 and print the output under 2 different columns namely User and Status. for eg. the output should like below: User Status ---- ------ a0crk_user A0-B0123 (3 Replies)
Discussion started by: mbak
3 Replies

9. Shell Programming and Scripting

gzcat into awk and then change FILENAME and process new FILENAME

I am trying to write a script that prompts users for date and time, then process the gzip file into awk. During the ksh part of the script another file is created and needs to be processed with a different set of pattern matches then I need to combine the two in the end. I'm stuck at the part... (6 Replies)
Discussion started by: timj123
6 Replies

10. Shell Programming and Scripting

using grep and print filename

Hi, I have a question on bash. Basically I would like to print a file name using bash. I am actually trying to grep a particular character in sequential files. I have alot files such that a.txt, b.txt,c.txt...etc. If I found a certain character, I would print that particular filename. I... (5 Replies)
Discussion started by: ahjiefreak
5 Replies
Login or Register to Ask a Question