Checking in a directory how many files are present and basing on that merge all the files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking in a directory how many files are present and basing on that merge all the files
# 8  
Old 01-02-2013
awk

Hey,

Try this one,

Code:
awk 'NR==1 || FNR>1{print;}'  file_list

Cheers,
RangaSmilie
# 9  
Old 01-02-2013
Hi,

Thank you for the reply.

can you pls tell me what's the difference between these two

Code:
awk 'NR==1 || FNR>1' flatfile1_v_*


Code:
awk 'NR==1 || FNR>1{print;}'  file_list


Last edited by radoulov; 01-02-2013 at 05:14 AM..
# 10  
Old 01-02-2013
Quote:
Originally Posted by srikanth_sagi
Hi,

Thank you for the reply.

can you pls tell me what's the difference between these two

awk 'NR==1 || FNR>1' flatfile1_v_*


awk 'NR==1 || FNR>1{print;}' file_list
Please use code tags for data samples and code.

Coming to the point, The both awk commands are same.
# 11  
Old 01-02-2013
Sorry for my negligence - should have been double equals:
Code:
$ awk 'NR==1; FNR>1' $(ls -t flatfile{1,2})
column1|column2|column3
4|5|6
1|1|
1|2|3
4||4

If you want files in creation time order, add the -r option to the $(ls ...) command substitution. If you don't care at all, use just sth like flatfile*.
Explanation:
NR==1: print very first line of entire stream (all files consecutively)
FNR>1: print all lines except first of respective file (i.e. lines >=2 in every single file)
ls -tr: supply files in creation date order
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to keep checking the directory for files.

Hello Folks, Looking for a script which can keep doing ls to the directories and once file landed to the directory then ,read the files do further calculation and exit. Kindly guide. Regards, Sadique (3 Replies)
Discussion started by: sadique.manzar
3 Replies

2. Shell Programming and Scripting

Merge multiple tab delimited files with index checking

Hello, I have 40 data files where the first three columns are the same (in theory) and the 4th column is different. Here is an example of three files, file 2: A_f0_r179_pred.txt Id Group Name E0 1 V N(,)'1 0.2904 2 V N(,)'2 0.3180 3 V N(,)'3 0.3277 4 V N(,)'4 0.3675 5 V N(,)'5 0.3456 ... (8 Replies)
Discussion started by: LMHmedchem
8 Replies

3. Shell Programming and Scripting

Merge files in a directory

Hey Guys, I want to merge all files (Apache Tomcat Access Logs) for a particular date say "Aug 24" to be merged into a single file. Is there any quick hack for that ? $ ls -alrth access_log2016-08-*|grep "Aug 24" -rw-rw-r--. 1 tomcat tomcat 16M Aug 24 00:00... (8 Replies)
Discussion started by: bluemind2005
8 Replies

4. Shell Programming and Scripting

Unzip all the files with subdirectories present and append a part of string from the main .zip files

Hi frnds, My requirement is I have a zip file with name say eg: test_ABC_UH_ccde2a_awdeaea_20150422.zip within that there are subdirectories on each directory we again have .zip files and in that we have files like mama20150422.gz and so on. Iam in need of a bash script so that it unzips... (0 Replies)
Discussion started by: Ravi Kishore
0 Replies

5. UNIX for Dummies Questions & Answers

Unable to find files, those can be present anywhere in the directory tree,based on its creation date

Hi I am unable to find files, those are present anywhere in the same directory tree, based on the creation date. I need to find the files with their path, as I need to create them in another location and move them. I need some help with a script that may do the job. Please help (2 Replies)
Discussion started by: sam192837465
2 Replies

6. Shell Programming and Scripting

UNIX :renaming the files present in the directory

Hi all, I am looking for a script which renames all the files from the present directory. Eg.: In unix directory contains the below files linux001.txt linux002.txt linux003.txt ...... ....... Now the files should be renamed to unix001.txt unix002.txt unix003.txt Could anyone... (8 Replies)
Discussion started by: scriptscript
8 Replies

7. Solaris

what is the use of each login related files present in users home directory

# ls -l total 10 -rw-r--r-- 1 dummy2 other 140 Jun 19 21:37 local.cshrc -rw-r--r-- 1 dummy2 other 136 Jun 19 21:37 local.cshrc~ -rw-r--r-- 1 dummy2 other 157 Jun 19 21:37 local.login -rw-r--r-- 1 dummy2 other 178 Jun 19 21:37 local.profile... (6 Replies)
Discussion started by: chidori
6 Replies

8. Solaris

Not able to edit files present in mounted directory

I had mount from server A to server B. I am able to access the files present under server B. I can create new files on server B, but i am not able to edit the files which are already present. When i saw the permissions on those files it is 777. can some one tell me why i am not able to edit... (2 Replies)
Discussion started by: subbaraju
2 Replies

9. Shell Programming and Scripting

Checking if the files in a directory have a txt extension

foreach file ($dir1/*) if ($file ~ *.txt) then echo "Skipping $file (is a txt file)" endif end that should work right guys? :confused: (15 Replies)
Discussion started by: pantelis
15 Replies

10. Shell Programming and Scripting

Checking the directory and concatenate the data of all the log files in that dir

Hi Gurus, I am new to unix and need your help to make a shell script. I have a requirement, would appreciate if you could please help me on it: Requirement: ------------- I will pass 2 parameters in shell script 1). Directory name say errors 2). file extension say .log First of all this... (4 Replies)
Discussion started by: anshulinpc
4 Replies
Login or Register to Ask a Question