naming files in awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers naming files in awk
# 8  
Old 09-07-2012
Quote:
Originally Posted by A-V
Delugeag? how would you put that in the line above to do the same thing?
The problem is wc -l give the line number and the filename. So 2 solutions :
Code:
test=$(wc -l $X | awk '{print $1}')

OR

test=$(cat $X | wc -l)

sorry.
# 9  
Old 09-07-2012
Pamu --> amazing Smilie works like magic
would it be possible to swap them around? having the file name first and then the line?
or because of the .txt its not possible?

delugeag --> I put in the loop I have but it does not do anything... i guess its because I dont call test anywhere
# 10  
Old 09-07-2012
Or
Code:
test=$(wc -l < $X)

# 11  
Old 09-07-2012
Quote:
Originally Posted by A-V
Pamu --> amazing Smilie works like magic
would it be possible to swap them around? having the file name first and then the line?
or because of the .txt its not possible?
Do you have all the files with .txt format..?

If yes, do this..

Not tested this, please check the output..

Below NR - row number and NM - file name
Code:
name=$($(basename $X) | sed 's/.txt//g')
    
awk -v NM="$name"'$0 != ""{ print > NR"-"NM".txt" }' $X

Hope this helps Smilie
This User Gave Thanks to pamu For This Post:
# 12  
Old 09-07-2012
test =...
creates file equal to the number of files and the lines

pamu --> gives the same error on the .txt
no worries Smilie in earlier stages when I make my file I can save them with no extension

Thanx

Last edited by A-V; 09-07-2012 at 10:44 AM..
# 13  
Old 09-07-2012
Quote:
Originally Posted by A-V
test =...
creates file equal to the number of files and the lines
pamu --> gives the same error on the .txt
no worries Smilie in earlier stages when I make my file I can save them with no extension
Thanx
Try this.. not able to run with basename(not working on my machine)
Used new code..
Try this,,Smilie

Code:
FILES="data/*"
for X in $FILES
do
    name=${X%.*}   #removes extensions of the file
    name_new=$(echo "$name" | awk -F "/" '{print $NF}')   # removes all the directory path - You can try just with echo for your desired outputs..
    awk -v NM="$name_new"'$0 != ""{ print > NM"-"NR".txt" }' $X 
done

I hope this helps youSmilie

Logging out...Smilie
This User Gave Thanks to pamu For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Concatenation of files with same naming patterns dynamically

Since my last threads were closed on account of spamming, keeping just this one opened! Hi, I have the following reports that get generated every 1 hour and this is my requirement: 1. 5 reports get generated every hour with the names "Report.Dddmmyy.Thhmiss.CTLR"... (5 Replies)
Discussion started by: Jesshelle David
5 Replies

2. Shell Programming and Scripting

Help with naming the file

Hi, I have a folder that contains files abc.txt def.txt ....and so on Inside abc.txt, I have @<TRIPOS>MOLECULE 4|Chelerythrine|abcb11_earlyIdentification_Stronginhib_washed_ligprep|sdf|1|dock Inside def.txt, I have @<TRIPOS>MOLECULE... (6 Replies)
Discussion started by: rossi
6 Replies

3. Shell Programming and Scripting

Naming output files based on variable parameters and input filenames

Hello, I have a series of files in sub-directories that I want to loop through, process and name according to the input filename and the various parameters I'm using to process the files. I have a number of each, for example file names like AG005574, AG004788, AG003854 and parameter values like... (2 Replies)
Discussion started by: bdeads
2 Replies

4. UNIX Desktop Questions & Answers

Combining files with specific patterns of naming in a directory

Greetings Unix exports, I am facing some problems in combining files with different name patterns with a directory and I would appreciate if you can help me I have more than 1000 files but they follow a specific pattern of naming. e.g. 64Xtest01.txt They are divided into two sets of test and... (9 Replies)
Discussion started by: A-V
9 Replies

5. Shell Programming and Scripting

Concatenate files to one file with naming convention

Hi , i have below files in wrk folder. file names are 1102090001.CLT 1102090003.CLT 1102100019.CLT 1102100020.CLT the above files are concatenate to one file but that concatenate file name must be same naming convention. (date +%y%m%d)and 0001 count. example : concatenate file... (9 Replies)
Discussion started by: krbala1985
9 Replies

6. Shell Programming and Scripting

Complex overlap and naming of 2 input files - Awk

for every specific $1,$2 check the values ($2,$3) of their E ot I of input1 and overlap with input2. Specify names based on output. ####### if middle value is missing name them "SE" if first value is missing name them "AFE" if last value is missing name them "ALE" if 2 middle values are... (1 Reply)
Discussion started by: ruby_sgp
1 Replies

7. Shell Programming and Scripting

#file naming

hi all, Please advise at what circumstance those file will become -rwxr-xr-x 1 psa psa 1969088 Aug 18 2006 #libaa.sl -rwx------ 1 psa psa 2166784 Jul 25 2006 #libcrypto.sl.0.9.7 -rwx------ 1 psa psa 904040 Jul 25 2006 #libxxx.sl -rwx------ 1 psa ... (2 Replies)
Discussion started by: rauphelhunter
2 Replies

8. UNIX for Dummies Questions & Answers

naming files that csplit creates

Hi, This is my first time on this forum.. I searched the previous answers, but didn't find the answer I was looking for at first glance. csplit works beautifully for me, except for one thing. My file looks like this: ad|name1|asdf...(several pages)..asdf ... ad|name2|asdf...(several... (8 Replies)
Discussion started by: juliette salexa
8 Replies

9. Programming

Naming a socket

Im not very experienced with C so this is probably a basic question. I have a script that opens up 5 sockets, it then runs through a loop and on a given event reconnects to the relevant socket and sends some data. The socket to be reconnected to is kept track of with a 'count' variable. The sockets... (5 Replies)
Discussion started by: geester
5 Replies

10. UNIX for Advanced & Expert Users

Controller Naming

Hello all, How does the Solaris identifies the controller subscript ? ( like c0txdxs0 or c1txdxsx ?? ) I have a unix box ( Ultra 30) running with 2.5.1. When I connected an external hard disk to the on-board scsi port, it got identified as c0t1dxsx... (... (1 Reply)
Discussion started by: shibz
1 Replies
Login or Register to Ask a Question