Remove head for all the files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove head for all the files
# 1  
Old 10-05-2011
Remove head for all the files

Hi all,

i need to remove the header for all the files which is ending with .csv and append into one file

example,
Code:
test1.csv
test2.csv
test3.csv

i tried with the below command,
Code:
sed '1d' test*.csv> appendnew.csv

but it deletes only the first file header. and appending all the files

Thanks,
baski

Last edited by Franklin52; 10-05-2011 at 09:00 AM.. Reason: Please use code tags, thank you
# 2  
Old 10-05-2011
Code:
$ for i in test*.csv; do sed '1d' $i >> append.csv; done

# 3  
Old 10-05-2011
A possible solution :
Code:
awk 'FNR>1' test*.csv> appendnew.csv

Jean-Pierre.
# 4  
Old 10-05-2011
Code:
awk 'FNR>1{print}' *.csv > out_file

--ahamed
# 5  
Old 10-05-2011
Quote:
Originally Posted by baskivs
Code:
sed '1d' test*.csv> appendnew.csv

but it deletes only the first file header. and appending all the files
Are you sure that its appending all the test*.csv files to appendnew.csv..? Try with >> instead of >
# 6  
Old 10-05-2011
Thanks for all your replies,

i m just expanding my query,

i can able to delete and append by using the below comman,
Code:
awk 'FNR>1{print}' *.csv >> out_file

and i aslo need some particular columns in the csv files , so i tried with this
Code:
awk -F"," -v OFS=',' '{print $1, $2,$8}' *csv >> outfile1

above also working fine but i need to merge it into single awk command and also need to sort the cloumns on w.r.t column $2
pls help me on this

thanks,
Baski

Last edited by vbe; 10-05-2011 at 09:47 AM.. Reason: please use code tags
# 7  
Old 10-05-2011
Code:
awk -F"," -v OFS="," 'FNR>1{print $1,$2,$8}' csv >> outfile1

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Paste multiple files, but only the sorted head -50

Hello, I want to merge multiple files (under hundreds folders) side by side. File name are the same but folder are different. like folder1/same_name.txt folder2/same_name.txt folder3/same_name.txt ......Normally it can be done as paste /different_path*/same_name.txt > merged_file.txtbut... (2 Replies)
Discussion started by: yifangt
2 Replies

2. Solaris

Command to remove existing files in the tar files in Solaris 10

Hi, I am using solaris 10 OS.Please help me out with the commands needed in below two scenarios. 1)How to delete the existing files in the tar file. suppose i have a main tarfile named application.tar and it contains a file called ingres.tar. what is the command to remove ingres.tar... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

3. Shell Programming and Scripting

Sed is doing my head in! How do you remove the first character of a string?

Hello! Please bare with me, I'm a total newbie to scripting. Here's the sudo code of what I'm trying to do: Get file name Does file exist? If true get length of file name get network id (this will be the last 3 numbers of the file name) loop x 2 If... (1 Reply)
Discussion started by: KatieV
1 Replies

4. UNIX for Dummies Questions & Answers

find and head -1

i have lots of files in /law/prod and /law/dev, such as AP20PD, AP20WS, AP20.scr, AP20.rpt if i am in /law DIR find . -name AP20PD, found in /law/prod and /law/dev i want to head -1 AP20PD from both location and >> /tmp/test.log can i use find and head in one line ? ----------... (1 Reply)
Discussion started by: tjmannonline
1 Replies

5. UNIX for Advanced & Expert Users

how to remove the files along with its link files

How to remove the files along with its link files either hardlink or softlink? (1 Reply)
Discussion started by: Ramesh_srk
1 Replies

6. Shell Programming and Scripting

compare two files and to remove the matching lines on both the files

I have two files and need to compare the two files and to remove the matching lines from both the files (4 Replies)
Discussion started by: shellscripter
4 Replies

7. Shell Programming and Scripting

Drop common lines at head/tail of a large set of files

Hi! I have a large set of pairs of text files (each pair in their own subdirectory) and each pair shares head/tail (a couple of first and last lines) but differs in the middle part. I need to delete the heads/tails and keep only the middle portions in which they differ. The lengths of heads/tails... (1 Reply)
Discussion started by: dobryden
1 Replies

8. Shell Programming and Scripting

head usage

$ct=1 head -n $ct file. When i used like this, i got an error , Bad usage of head Cant we use variables in place of number in HEAD. In my requirement for every iteration i should increase the number in Head and tail the last one. HOw can i achieve this (5 Replies)
Discussion started by: vasuarjula
5 Replies

9. Shell Programming and Scripting

head command

Hi All, How can the head command be used to extract only a particular line. By default head -n filename displays the first n lines. I want only the nth line. I couldn't get it from forum search. Thanks, Sumesh (6 Replies)
Discussion started by: sumesh.abraham
6 Replies

10. UNIX for Dummies Questions & Answers

help.. I am in way over my head !!!!

my boss has done it again I have been sent to fix a unix issue and I ma hoping you can help three issues 1st. I have a printer that when you try to print to it the print job comes out on a diffrent printer. If I take the printer ( dot matrix thourgh a serail connection) to a diffrent local the... (3 Replies)
Discussion started by: oberon42
3 Replies
Login or Register to Ask a Question